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()
ab_found = False
ba_found = False

# Find the first occurrence of "AB"
x1 = s.find("AB")
if x1 != -1:
    # Find the occurrence of "BA" after the first "AB"
    x2 = s.find("BA", x1 + 2)
    if x2 != -1:
        ab_found = True

# Find the first occurrence of "BA"
y1 = s.find("BA")
if y1 != -1:
    # Find the occurrence of "AB" after the first "BA"
    y2 = s.find("AB", y1 + 2)
    if y2 != -1:
        ba_found = True

# Check if either "AB" followed by "BA" or "BA" followed by "AB" is found
if ab_found or ba_found:
    print("YES")
else:
    print("NO")
