AtCoder Regular Contest 145
A
AB Palindrome
AtCoder
⌀ 596
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given a string $S$ of length $N$ consisting of A and B.

翻译中…

You can repeat the following operation zero or more times:

翻译中…
  • choose a pair of adjacent characters in $S$ and replace them with AB.
翻译中…

Determine whether $S$ can be turned into a palindrome.

翻译中…

What is a palindrome? A string $T$ is a palindrome if and only if, for every integer $i$ ($1 \le i \le |T|$), the $i$-th character from the beginning and the $i$-th character from the end are the same, where $|T|$ is the length of $T$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 2\times 10^5$
  • $S$ is a string of length $N$ consisting of A and B.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
S

翻译中…

Output

翻译中…

If $S$ can be turned into a palindrome, print Yes; otherwise, print No.

翻译中…

样例

Input #1
3
BBA
Output #1
Yes
Replacing the $2$-nd and $3$-rd characters, `BA`, with `AB` will turn $S$ into `BAB`, a palindrome.
Input #2
4
ABAB
Output #2
No
No sequence of operations can turn $S$ into a palindrome.
题目信息
题号
arc145_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。