Codeforces Round 306 (Div. 2)
A
Two Substrings
Codeforces
1500
原题
←B →
翻译中…

You are given string $*s*$. Your task is to determine if the given string $*s*$ contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

翻译中…

Input

翻译中…

The only line of input contains a string $*s*$ of length between $1$ and $10^{5}$ consisting of uppercase Latin letters.

翻译中…

Output

翻译中…

Print "YES" (without the quotes), if string $*s*$ contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

翻译中…

Note

翻译中…

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

翻译中…

In the second sample test there are the following occurrences of the substrings: BACFAB.

翻译中…

In the third sample test there is no substring "AB" nor substring "BA".

翻译中…

样例

Input #1
ABA
Output #1
NO
InputCopy OutputCopy
Input #2
BACFAB
Output #2
YES
InputCopy OutputCopy
Input #3
AXBYBXA
Output #3
NO
InputCopy OutputCopy
题目信息
题号
550A
时间限制
2 s
内存限制
256 MB
标签
暴力
动态规划
贪心
模拟
字符串

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