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 solve():
    s = input()
    abi0 = s.find('AB', 0)
    abi1 = s.find('AB', abi0+1) if abi0 != -1 else -1
    abi2 = s.find('AB', abi1+1) if abi1 != -1 else -1

    bai0 = s.find('BA')
    if bai0 == -1:
        return False
    
    if abi0 != -1 and abi0 != bai0-1 and abi0 != bai0+1:
        return True
    
    if abi1 != -1 and abi1 != bai0-1 and abi1 != bai0+1:
        return True
    
    if abi2 != -1 and abi2 != bai0-1 and abi2 != bai0+1:
        return True
    
    return False

if solve():
    print('YES')
else:
    print('NO')


