2622: CF550 - A. Two Substrings
[Creator : ]
Description
You are given strings. Your task is to determine if the given stringscontains 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.
Sample 1 Input
ABA
Sample 1 Output
NO
despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
Sample 2 Input
BACFAB
Sample 2 Output
YES
there are the following occurrences of the substrings: BACFAB.
Sample 3 Input
AXBYBXA
Sample 3 Output
NO
there is no substring "AB" nor substring "BA".