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.
s = input().strip()

a_indices = [i for i in range(len(s)) if s[i] == 'A']
b_indices = [i for i in range(len(s)) if s[i] == 'B']

if len(a_indices) >= 2 and len(b_indices) >= 2:
    # Check if there is at least one occurrence of 'AB' and one occurrence of 'BA'
    ab_found = False
    ba_found = False
    for i in range(len(s)-1):
        if s[i:i+2] == 'AB' and i in a_indices and i+1 in b_indices:
            ab_found = True
        elif s[i:i+2] == 'BA' and i in b_indices and i+1 in a_indices:
            ba_found = True
        if ab_found and ba_found:
            print('YES')
            break
    else:
        print('NO')
else:
    print('NO')