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.
string = [char for char in input()]
storage = ["" for i in string]
def solve():
    for i in reversed(range(len(storage)-1)):
        storage[i] = storage[i+1]
        if string[i] == "A":
            if string[i+1] == "B":
                storage[i] = "AB"
                if i+2<len(storage)and (storage[i+2] == "BA" or storage[i+2] == "either"):
                    return "YES"
                elif storage[i+1] == "BA":
                    storage[i] = "either"
        if string[i] == "B":
            if string[i+1] == "A":
                storage[i] = "BA"
                if i+2<len(storage) and (storage[i+2] == "AB" or storage[i+2] == "either"): 
                    return "YES"
                elif storage[i+1] == "AB":
                    storage[i] = "either"
    return "NO"
print(solve())