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=list(input());v=[]
# for i in range(0,len(x)-1):
#     a=x[i]+x[i+1]
#     v.append(a)
# print(x.index("B")+1)
# print(x.index(("B"),x.index("B")+1)+1) 
# print(x[((x.index(("B"),x.index("B")))+1)+1])
# if x.count("A")>1 and x.count("B")>1:    
#   if x[(x.index("A")+1)]=="B" and x[((x.index(("B"),x.index("B")))+1)+1]=="A" and (x.index(("B"),x.index("B")+1))+1<len(x) :
#     print("YES")
#   else:
#      print("NO")  
# else:
#     print("NO")
i=0
c=0
c1=0
while i<len(x)-1:
    if x[i]=="A" and x[i+1]=="B" and c<1:
        i=i+2
        c=c+1
    elif x[i]=="B" and x[i+1]=="A" and c1<1 :
        i=i+2
        c1=c1+1    
    else:
        i=i+1 
# print(c,c1)        
if c>=1 and c1>=1:
    print("YES")
else:
    print("NO")    
