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.
# https://codeforces.com/problemset/problem/550/A

def check(w):
    s, k = 0, 0
    r_a, r_b = set(), set()
    while k != -1:
        k = w.find('AB', s)
        if k != -1:
            s = k + 1
            r_a.add(s)
    
    s, k = 0, 0
    while k != -1:
        k = w.find('BA', s)
        if k != -1:
            s = k + 1
            r_b.add(s)

    if len(r_a) == 0 or len(r_b) == 0:
        return 'NO'

    if len(r_a) == 1 and len(r_b) == 1:
        if r_a.pop() == r_b.pop() - 1:
            return 'NO'
    
    return 'YES'

print(check(input()))