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.
'''
x = int(input())
List = []
element = None
flag1 = 0
flag2 = 0
first_club = None
second_club = None

for q in range(x):
    element = input()
    List.append(element)

List.sort(key=str.lower)

for i in range(len(List)):
    if List[i] != List[x-1]:
        flag1 += 1
        first_club = List[i]
    else:
        second_club = List[i]

if flag1 > (x/2):
    print(first_club)
else:
    print(second_club)
'''

stroka=input()
j=-1
flag=0

if len(stroka)==3:
    print("NO")
for i in range(len(stroka)):
    if (stroka[i]=="A" and stroka[i+1]=="B") or (stroka[i]=="B" and stroka[i+1]=="A"):
        while j>-len(stroka):
            if (stroka[j]=="A" and stroka[j-1]=="B") or (stroka[j]=="B" and stroka[j-1]=="A"):
                flag = 0
                break
            else:
                flag=1
            j-=1
    else:
        flag=1

if flag==1:
    print("NO")
else:
    print("YES")
#for i in range(len(stroka)):
    #if (stroka[i]=="A" and stroka[i+1]=="B") or (stroka[i]=="B" and stroka[i+1]=="A"):


