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)

sABBA = ['AB', 'BA']
i = j = 0
sBAAB = ['BA', 'AB']
k = l = 0
found = False

ni = {(0,0): (0,1), (0,1): (1,0), (1,0): (1,1), (1,1): (-1,-1)}

for ch in s:
    if ch == sABBA[i][j]:
        i, j = ni[(i,j)]
    else:
        j = 0
    if ch == sBAAB[k][l]:
        k, l = ni[(k,l)]
    else:
        l = 0
    if i == -1 or k == -1:
        found = True
        break

print('YES' if found else 'NO')
    