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()
i = 0
j = len(s)-1
ans = "NO"
while i < j:
    if s[i] == "A":
        if s[i+1] == "B" and i< j-1:
            i = i
        else:
            i += 1
    else:
        i += 1
    if s[j] == "A":
        if s[j-1] == "B" and j-1 > i+1:
            j = j
        else:
            j -= 1
    else:
        j -= 1
    if s[i] == "A" and s[i+1] == "B" and i+1<j-1 and s[j]=="A" and s[j-1] == "B":
        ans = "YES"
        i = 100
        j=0
if ans == "NO":
    i = 0
    j = len(s) - 1
    while i < j:
        if s[i] == "B":
            if s[i + 1] == "A" and i < j - 1:
                i = i
            else:
                i += 1
        else:
            i += 1
        if s[j] == "B":
            if s[j - 1] == "A" and j - 1 > i + 1:
                j = j
            else:
                j -= 1
        else:
            j -= 1
        if s[i] == "B" and s[i + 1] == "A" and i + 1 < j - 1 and s[j] == "B" and s[j - 1] == "A":
            ans = "YES"
            i = 100
            j = 0

print(ans)