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 math
from collections import Counter
from collections import defaultdict as ddc

def li(): return list(map(int,input().split()))

def nt(): return int(input())

def st(): return input()

#------------------------------------------------------------------------

yes="YES"
no="NO"
even="EVEN"
odd="ODD"
mod=998244353

#------------------------------------------------------------------------
            

def prefix(L):
    size=len(L)
    for i in range(size-1):
        L[i+1]=L[i]+L[i+1]
    return L

def exponentiation(bas, exp, mod):
    t = 1
    while(exp > 0): 
  
        if (exp % 2 != 0):
            t = (t * bas) % mod
  
        bas = (bas * bas) % mod 
        exp //= 2
    return t % mod

def binlist(x):
    L=[0]*21
    temp=bin(x)
    temp=temp[2:]
    x=len(temp)
    indexL=[]
    for i in range(x-1,-1,-1):
        if temp[i]=='1':
            L[x-i]=1
            indexL.append(x-i)
    return L
    
def binlisttoint(L):
    x=0
    for i in range(1,21):
        if L[i]=='1':
            x+=2**(i-1)
    return x
#------------------------------------------------------------------------    

#for _ in range(int(input())):
string=input()
a=string.find('AB')
b=string.find('BA',a+2)
c=string.find('BA')
d=string.find('AB',c+2)
if((a!=-1 and b!=-1) or (c!=-1 and d!=-1)):
    print('YES')
else:
    print('NO')
