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.
str = input()
l1 = []
l2 = []

start = 0

while start < len(str):
    idx1 = str.find("AB", start)
    if idx1 != -1:
        l1.append(idx1)
        start = idx1 + 2
    else:
        break

start = 0

while start < len(str):
    idx2 = str.find("BA", start)
    if idx2 != -1:
        l2.append(idx2)
        start = idx2 + 2
    else:
        break

if (len(l1) == 0 or len(l2) == 0) or (l1 == l2) or (len(l1) == 1 and len(l2) == 1 and abs(l1[0] - l2[0]) == 1):
    print("NO")
else:
    print("YES")


 	 				  		   		    	   	 		  	