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()
lists=["AB","BA"]
lists1=["AB","BA"]
lists2=["BA","AB"]
st=""
nlists=[]
count=0
d=1
for i in s:
    if (i=="A" or i=="B") and i not in st and count==0:
        st+=i
        if st in lists:
            nlists.append(st)
            lists.remove(st)
            st=""
            count+=1
    elif (i=="A" or i=="B") and i not in st and count==1:
        if i==nlists[0][d]:
            st+=i
            d-=1
            if st in lists:
                nlists.append(st)
                lists.remove(st)
                break
    elif st=="A" and i!="B":
        st=""
    elif st=="B" and i!="A":
        st=""

if nlists==lists1 or nlists==lists2:
    print("YES")
else:
    print("NO")
