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.
# 5 Two Substrings 13m https://codeforces.com/problemset/problem/1/A
#  O()t | O()s 03:31

def overlap(sub1, sub2):
#     print(sub1, sub2)
    for i in range(len(sub1)):
        for j in range(len(sub2)):
#             print(sub1[i], sub2[len(sub2) - j - 1], abs(sub1[i] - sub2[len(sub2) - j - 1]))
            if abs(sub1[i] - sub2[j]) > 1: return False            
    return True
    
def two_substrings(string):
#     print(string)
    sub1, sub2 = [], []
    for i in range(len(string) - 1):
        if string[i] == "A" and string[i + 1] == "B":
            sub1.append(i)
        if string[i] == "B" and string[i + 1] == "A":
            sub2.append(i)
        if sub1 and sub2 and not overlap(sub1, sub2):
            print("YES")
            return
    print("NO")
                
string = input()
two_substrings(string)

# two_substrings("ABABA") # = YES
# two_substrings("ABAAB") # = YES
# two_substrings("ABA") # = NO
# two_substrings("BACFAB") # = YES
# two_substrings("AXBYBXA") # = NO