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.
 
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#print = lambda x: sys.stdout.write(str(x) + "\n")
    
II = lambda: int(input())
MII = lambda: map(int, input().split())
LMII = lambda: list(MII())
#SLMII = lambda: sorted(LMII())

s = input()
n = len(s)

def isWordInStr(s, word):
    m = len(word)
    n = len(s)
    for k in range(n-m+1):
        for i in range(m):
            if s[k+i] != word[i]:
                break
        else:
            return k+m
            
    return -1
        
pos1 = isWordInStr(s, 'AB')
pos2 = isWordInStr(s, 'BA')

fABBA = fBAAB = False
if pos1 != -1 and isWordInStr(s[pos1:], 'BA') != -1:
    fABBA = True
if pos2 != -1 and isWordInStr(s[pos2:], 'AB') != -1:
    fBAAB = True
    
print('YES' if fABBA or fBAAB else 'NO')
    
    
