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 = "AB"
x2 = "BA"
c1 = 1
c2 = 1
l1 = []
l2 = []
l3 = []

pairs = pairwise(s)
for i, j in pairs:
    pair = i + j
    if pair == x1:
        if c1 % 2:
            l1.append('$')
        else:
            l1.append('$')
            l3.append('#')
        c2 += 1
        continue
    elif pair == x2:
        if c2 % 2:
            l2.append('$')
        else:
            l2.append('$')
            l3.append('#')
        c1 += 1
        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')