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())):
s=st()
yes=False
ABf=False
BAf=False
c=0
for i in range(len(s)-1):
    if s[i]+s[i+1]=="AB":
        ABf=True
        if s[i-1]=="B":
            yes=True
            c+=1
        else:
            yes=False
    if s[i]+s[i+1]=="BA":
        BAf=True
        if s[i-1]=="A":
            yes=True
            c+=1
        else:
            yes=False
if ABf and BAf and (c==0 or c>1):
    print("YES")
else:
    print("NO")
