← Back to List

22403번: 阿吽の呼吸 ↗

Solutions

Python 3
171 B | 171 chars
c = 0
chk = 1
for _ in ' '*int(input()):
  if input() == 'A':
    c += 1
  else:
    if c > 0:
      c -=1
    else:
      chk = 0
print("YES" if chk and c == 0 else "NO")