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="kl"
    y="j"
    z="k"
    a="a"
    for i in range(n-1):
        if s[i]=="A" and s[i+1]=="B":
            x=i
    for i in range(n-1):
        if s[i]=="B" and s[i+1]=="A":
            y=i
    for i in range(n-2,-1,-1):
        if s[i]=="A" and s[i+1]=="B":
            z=i
    for i in range(n-2,-1,-1):
        if s[i]=="B" and s[i+1]=="A":
            a=i
    if type(x)==int and type(a)==int:
        if abs(x-a)>1:
            return "YES"
    if type(y)==int and type(z)==int:
        if abs(y-z)>1:
            return "YES"
    return "NO"
x=input()
print(f(x))
