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.

from collections import defaultdict

def solve(s):
    dic = defaultdict(int)
    i = 0
    n = len(s)
    while i<n:
        # print(i)
        if(s[i]=="A"):
            i+=1
            if(i<n and s[i]=="B"):
                i+=1
                if(i<n and s[i]=="A"):
                    i+=1
                    dic["maybe"]+=1
                else:
                    dic["ab"]+=1
        
        elif(s[i]=="B"):
            i+=1
            if(i<n and s[i]=="A"):
                i+=1
                if(i<n and s[i]=="B"):
                    i+=1
                    dic["maybe"]+=1
                else:
                    dic["ba"]+=1
        else:
            i+=1
    if(dic["ab"]>0 and dic["ba"]>0):
        return "YES"
    if(dic["ab"]>0 and dic["maybe"]>0):
        return "YES"
    if(dic["maybe"]>0 and dic["ba"]>0):
        return "YES"
    return "NO"
            





s = input()
print(solve(s))