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.
str = input()

# Index of the first occurrence of "AB" and "BA"
first_index_ab = str.find("AB")
first_index_ba = str.find("BA")

# Index of the last occurrence of "AB" and "BA"
last_index_ab = str.rfind("AB")
last_index_ba = str.rfind("BA")

# Check if any of the `first_index_ + 1`
# is not equal to any of the `last_index_`
if (first_index_ab != -1) and (first_index_ba != -1) \
        and (first_index_ab+1 < last_index_ba or first_index_ba+1 < last_index_ab):
    print("YES")
else:
    print("NO")
