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()
lst1 = []
lst2 = []
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'B':
        lst2.append(s[i])
    else:
        lst1.append(lst2)
        lst2 = []

lst1.append(lst2)
dict1 = {'ABA':0,'BAB':0,'AB':0,'BA':0}
for i in range(len(lst1)):
    lst2 = ''.join(lst1[i])
    i = 0
    # print(lst2)
    while(i<len(lst2)):
        j = min(3,len(lst2)-i)
        if j == 3:
            if lst2[i:j] in dict1:
                dict1[lst2[i:j]]+=1
                i+=3
            elif lst2[i:j-1] in dict1:
                dict1[lst2[i:j-1]]+=1
                i+=2
            else:
                i+=1
        elif j == 2:
            if lst2[i:j] in dict1:
                dict1[lst2[i:j]]+=1
                i+=2
            else:
                i+=1
        else:
            i+=1
    
if dict1['ABA']>=2 or dict1['BAB']>=2:
    print('YES')
if dict1['AB'] >=1 and dict1['BA'] >= 1:
    print('YES')
elif (dict1['ABA'] == 1 and dict1['AB']>=1) or (dict1['ABA'] == 1 and dict1['AB']>=1) or (dict1['BAB'] == 1 and dict1['AB']>=1) or (dict1['BAB'] == 1 and dict1['BA']>=1):
    print('YES')
else:
    print('NO')