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.
'''d=str(input())
n=0
s=0
l=[]
s=[]
for i in range(len(d)-1):
    l.append(d[i:i+2])

for i in range(1):
    if len(d)<=3:
        s.append("NO")
        break
    else:
        for i in range(len(l)):
            if i==len(l)-1:
                s.append("NO")
            elif l[i] == "AB":
                e=l[i+2:len(l)]
                if e.count("BA")>0:
                    s.append("YES")
                else:
                    s.append("NO")

            elif l[i] == "BA":
                g=l[i+2:len(l)]
                if g.count("AB")>0:
                    s.append("YES")
                else:
                    s.append("NO")
print(s[0])'''
d = str(input())
n = len(d)
l = []
m=[]
p=[]

for i in range(n-1):
    l.append(d[i:i+2])
if "AB" not in d or "BA" not in d or len(d) <= 3:
    print("NO")
else:
    for i in range(len(l)):
        if l[i]=="AB":
            m.append(i)
        elif l[i]=="BA":
            p.append(i)
    if len(m)>1 and len(p)>1:
        print("YES")
    else:
        if abs(m[0]-p[0])>1:
            print("YES")
        else:
            print("NO")



