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 solve(string):
    l = len(string)
    i = 1
    substrings = ["AB", "BA"]
    for substr in substrings:
        if substr not in string:
            return False

    while i < l:
        substring = string[i-1:i+1]
        for substr1, substr2 in zip(substrings, substring[::-1]):
            if substring == substr1 and substr2 in string[i+1:]:
                return True
        i += 1


def main():
    string = input()
    print("YES" if solve(string) else "NO")

main()
