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 bisect import bisect
import math
from collections import defaultdict



    
def solve():
    s = input()
    dpa = [False for _ in s]
    dpb = [False for _ in s]

    for i in range(len(s) - 2, -1, -1):
        if s[i] == 'A' and s[i + 1] == 'B':
            dpa[i] = True
            if i + 2 < len(s) and dpb[i + 2]:
                print("YES")
                return

        if s[i] == 'B' and s[i + 1] == 'A':
            dpb[i] = True
            if i + 2 < len(s) and dpa[i + 2]:
                print("YES")
                return
        
        dpa[i] = dpa[i] or dpa[i + 1]
        dpb[i] = dpb[i] or dpb[i + 1]

    print("NO")

tc = 1 # int(input())

for i in range(tc):
    solve()