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.
def f(s):
    n=len(s)
    x=0
    y=0
    z=0
    a=0
    for i in range(n-1):
        if s[i]=="A" and s[i+1]=="B":
            x=i
            break
    for i in range(n-1):
        if s[i]=="B" and s[i+1]=="A":
            y=i
            break
    for i in range(n-1):
        if s[n-i-2]=="B" and s[n-i-1]=="A":
            z=n-i-2
            break
    for i in range(n):
        if s[n-i-2]=="A" and s[n-i-1]=="B":
            a=n-i-2
            break
    if abs(x-z)>1 or abs(y-a)>1:
        return "YES"
    return "NO"
s=input()
print(f(s))

