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.
s = input()

pointer = 0
found = ""
backup = ""
modeOn= False

while pointer < len(s)-1:
    current = s[pointer]
    if (current != "A" and current!="B") or current == found:
        pointer+=1
        continue
    nextt = s[pointer+1]
    try:
        moreFuture = s[pointer+2]
    except:
        pass
    if current == "A" and nextt == "B":
        if moreFuture == "A":
            backup += "B"
        found += "A"
        if len(found) == 2:
            print("YES")
            break
        pointer+=1
    elif current == "B" and nextt == "A":
        if moreFuture == "B":
            backup += "A"
        found += "B"
        if len(found) == 2:
            print("YES")
            break
        pointer+=1   
    pointer+=1
else:
    if found + backup == "AB" or found + backup == "BA":
        print("YES")
    else:
        print("NO")
