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).
The only line of input contains a string *s* of length between 1 and 10<sup class="upper-index">5</sup> consisting of uppercase Latin letters.
#https://codeforces.com/problemset/problem/550/A

s = input()
a_b, b_a = [x for x in range(len(s)) if s.startswith("AB", x)], [x for x in range(len(s)) if s.startswith("BA", x)]
try:
    min_ab, min_ba = min(a_b), min(b_a)
    max_ab, max_ba = max(a_b), max(b_a)
    if(abs(min_ab - max_ba) > 1 or abs(min_ba - max_ab) > 1):
        answer = "YES"
    else:
        answer = "NO"
except:
    answer = "NO"
print(answer)