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):
    # 如果字符串长度小于等于3，则直接返回'NO'
    if len(string) <= 3:
        return 'NO'

    # 找到AB和BA的索引
    AB_index = []
    BA_index = []
    for i in range(len(string) - 1):
        if string[i:i+2] == 'AB':
            AB_index.append(i)
        elif string[i:i+2] == 'BA':
            BA_index.append(i)

    # 检查AB和BA的索引是否有非重叠的部分
    for j in AB_index:
        for x in BA_index:
            if x <= j-2 or x >= j+2:
                return 'YES'
    
    return 'NO'

string = input()
print(judge(string))
