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 find_substring(string: str, substring: str):
    index = -1
    indices = []
    while(True):
        index = string.find(substring, index + 1)
        if index == -1:
            break
        indices.append(index)
    return indices

string = input().lower()
result = False
indexes = find_substring(string, "ab")
for index in indexes:
    for i in range(1, len(string)):
        if string[i] == 'a' and string[i - 1] == 'b':
            overlap = abs(i - 1 - index)
            if overlap >= 2:
                result = True
                break
if result:
    print('YES')
else:
    print('NO')