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.
# Nhập chuỗi
string = input("Nhập chuỗi: ")

# Tạo list chứa index của các phần tử A
a_index = []
for i in range(len(string)):
    if string[i] == 'A':
        a_index.append(i)

b_back = [x + 1 for x in a_index if x < len(string) - 1]
b_front = [x - 1 for x in a_index if x > 0]

all_loc_b_back = []
all_loc_b_front = []
#
for j in b_back:
    if string[j] == 'B':
        loc_ab = str(j-1) + str(j)
        all_loc_b_back.append(loc_ab)
for k in b_front:
    if string[k] == 'B':
        loc_ba = str(k) + str(k+1)
        all_loc_b_front.append(loc_ba)

for str_a in all_loc_b_back:
    for str_b in all_loc_b_front:
        intersection_result = set(str_a).intersection(str_b)
        if len(intersection_result) != 0:
            all_loc_b_back.remove(str_a)
            all_loc_b_front.remove(str_b)

if (len(all_loc_b_front) != 0) or (len(all_loc_b_back) != 0):
    print('YES')
else:
    print('NO')

