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=input()
def cal(pat):
    m=len(pat)
    lps=[0]*m
    i=1
    length=0
    while i<m:
        if lps[i]==lps[length]:
            length+=1
            lps[i]=length
            i+=1
        else:
            if length==0:
                i+=1
            else:
                length=lps[length-1]
    return lps
def match(text,pat):
    n=len(text)
    m=len(pat)
    i=0
    j=0
    lps=cal(pat)
    indices=[]
    while i<n:
        if text[i]==pat[j]:
            i+=1
            j+=1
            if j==m:
                indices.append(i-j)
                j=lps[j-1]
                i+=1
        else:
            if j==0:
                i+=1
            else:
                j=lps[j-1]
                i+=1
    return indices
pat_AB=match(s,'AB')
pat_BA=match(s,'BA')
ia=0
ib=0
na=len(pat_AB)
nb=len(pat_BA)
flag=True
# print(pat_AB,pat_BA)
for ia in range(na):
    for ib in range(nb):
        if abs(pat_AB[ia]-pat_BA[ib])==1:
            flag=False
            print("NO")
            break
    if not flag:
        break
if not(pat_AB and pat_BA):
    print("NO")
elif flag:
    print("YES")