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
l=[]
s=[]
for i in range(len(d)-1):
    l.append(d[i:i+2])
found_match = True
for i in range(1):
    if len(d)<=3:
        s.append("NO")
        found_match = False
    elif  l[i] == "AB" and found_match:
        for i in range(len(l)):
            if i==len(l)-1:
                s.append("NO")
                found_match = False
            elif l[i] == "AB":
                e=l[i+2:len(l)]
                if e.count("BA")>0:
                    s.append("YES")
                    found_match = False
                else:
                    s.append("NO")
                    found_match = False
            elif l[i] == "BA" and found_match:
                g=l[i+2:len(l)]
                if g.count("AB")>0:
                    s.append("YES")
                    found_match = False
                else:
                    s.append("NO")
                    found_match = False


print(s[0])'''
d = str(input())
found_match = False

for i in range(len(d)-1):
    if d[i:i+2] == "AB":
        if "BA" in d[i+2:]:
            found_match = True
            break
    elif d[i:i+2] == "BA":
        if "AB" in d[i+2:]:
            found_match = True
            break

if found_match:
    print("YES")
else:
    print("NO")
