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 matcher(s):
    patterns = ['AB', 'BA']
    for p in [patterns, patterns[::-1]]:
        one = s.find(p[0])
        sec = s.find(p[1], one + 2)
        if is_valid(one, sec): return True
    return False

def is_valid(first, sec):
    if first == -1 or sec == -1: return False
    return abs(first - sec) > 1

s = input()
print('YES' if matcher(s) else 'NO')