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.
from collections import deque

'''

    9XZER0

'''

def intin():
    return int(input())
def listin():
    return [int(i) for i in input().split()]
def mapin():
    return map(int,input().split())


if __name__ == "__main__":

    s = input()
    s_AB = s.find('AB')
    #print(s_AB)
    s_BA = s.find('BA', s_AB+2)
    #print(s_BA)

    r_AB = s.find('BA')
    #print(r_AB)
    r_BA = s.find('AB', r_AB+2)
    #print(r_BA)

    con = (s_AB!=-1 and s_BA!=-1) or (r_AB!=-1 and r_BA!=-1)

    if(con):
        print("YES")
    else:
        print("NO")
