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.

if __name__=='__main__':
    s_arr = input()
    n_arr = []
    for i in s_arr:
        n_arr.append(i)
    # print(s_arr, n_arr)
    ab1 = 0
    ba1 = 0
    ab2=0
    ba2=0
    i = 0
    while 1:
        if i==len(n_arr)-1:
            break
        if n_arr[i]=='A' and n_arr[i+1]=='B':
            ab1=1
            i+=2
            break
        i+=1
    j = i
    while 1:
        if j>=len(n_arr)-1:
            break
        if n_arr[j]=='B' and n_arr[j+1]=='A':
            ba1=1
            break
        j+=1    
    i = 0
    while 1:
        if i==len(n_arr)-1:
            break
        if n_arr[i]=='B' and n_arr[i+1]=='A':
            ba2=1
            i+=2
            break
        i+=1
    j = i
    while 1:
        if j>=len(n_arr)-1:
            break
        if n_arr[j]=='A' and n_arr[j+1]=='B':
            ab2=1
            break
        j+=1    
    
    if ab1 and ba1:
        print("YES")
    elif ab2 and ba2:
        print("YES")
    else:
        print("NO")