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.
txt = str(input())
text = []
indexa = 0
indexb = 0
indexa2 = 0
indexb2 = 0
first = None
second = None
first2 = None
second2 = None

for i in txt:
    text.append(i)

for x in text:
    if x == "A":
        A = indexa
        break
    indexa += 1
for x in text:
    if x == "B":
        B = indexb
        break
    indexb += 1

if indexa == indexb + 1:
    first = True

for x in text:
    if x == "B":
        A2 = indexa2
        break
    indexa += 1
for x in text:
    if x == "B":
        B = indexb
        break
    indexb += 1

if indexa2 == indexb2 + 1:
    first = True

if first == True:
    print('YES')
else:
    print('NO')