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 judge(string):
    if len(string)<=3:
        return 'NO'
    for i in range(len(string)):
        if string[i:i+2]=='AB':
            AB_index.append(i)
        elif string[i:i+2]=='BA':
            BA_index.append(i)
    for j in AB_index:
        if len([x for x in BA_index if x<=j-2 or x>=j+2])!=0:
            return 'YES'
    return 'NO'

AB_index=[]
BA_index=[]
string=input()
print(judge(string))