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 itertools import pairwise
s=input()
x1=('A', 'B')
x2=('B', 'A')
c1=1;c2=1;l1=[];l2=[];l3=[]
z=pairwise(s)
for i in z:
    if i==x1:
        if c1%2:
            l1.append('$')
            c2+=1
            continue
        else:
            l1.append('$')
            c2+=1
            l3.append('#')
            continue
    elif i==x2:
        if c2%2:
            l2.append('$')
            c1+=1
            continue
        else:
            l2.append('$')
            c1+=1
            l3.append('#')
            continue
    c1,c2=1,1
     
if len(l1)+len(l2)>2:
    print('YES')
elif len(l1)+len(l2)==2 and len(l3)==0:
    print('YES')
else:
    print('NO')