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 sys
input = sys.stdin.readline

def f(n,prev):
    if n > length :
        return 0
    if (n,prev) in memo :
        return memo[n,prev]
    if arr[n] == 3:
        x = 1
        y = 2
        dx = 1 if prev == 1 else 0
        dy = 1 if prev == 2 else 0
        memo[n,prev] = min( dy + f(n+1,y) ,dx + f(n+1,x) )
        return memo[n,prev]
    if arr[n] == prev or arr[n] == 0:
        memo[n,prev] = 1+f(n+1,0)
        return memo[n,prev]
    else :
        memo[n,prev] = f(n+1,arr[n])
        return memo[n,prev]

s = input()
i = 1
check = set()
bef = s[0]
while i < len(s) - 1 :
    new = bef + s[i]
    if new == "BA" or new == "AB" :
        i += 1
        check.add(new)
    bef = s[i]
    i += 1
print("YES") if len(check) == 2 else print("NO")
