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.
s = str(input())
n = len(s)
pref = [[0, 0] for i in range(len(s))]
suff = [[0, 0] for i in range(len(s))]
for i in range(1, n):
    pref[i][0] = pref[i - 1][0]
    pref[i][1] = pref[i - 1][1]
    if(s[i - 1] == "A" and s[i] == "B"): pref[i][0] += 1
    if(s[i - 1] == "B" and s[i] == "A"): pref[i][1] += 1
for i in range(n - 2, -1, -1):
    suff[i][0] = suff[i + 1][0]
    suff[i][1] = suff[i + 1][1]
    if(s[i + 1] == "B" and s[i] == "A"): suff[i][0] += 1
    if(s[i + 1] == "A" and s[i] == "B"): suff[i][1] += 1

for i in range(1, n - 1):
    if(pref[i][0] and suff[i + 1][1] or pref[i][1] and suff[0]):
        print("YES")
        exit(0)
print("NO")
