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.
import heapq
import sys
from collections import deque
from math import sqrt, ceil, floor
import string

# sys.setrecursionlimit(10**7)
# mod = 1_000_000_007

input = sys.stdin.readline
print = sys.stdout.write
def search(a,b):
    visited = [False]*len(s)
    flag1 = False
    flag2 = False
    for i in range(len(s)):
        if s[i:i+2] == a and not visited[i]:
            visited[i] =True
            visited[i+1] = True
            flag1 =True

    for i in range(len(s)):
        if s[i:i+2] == b and not visited[i]:
            visited[i] =True
            visited[i+1] = True
            flag2 =True
    return flag1 and flag2

s = input().rstrip()
val1 = search("AB","BA")
val2 = search("BA","AB")

if val1 and val2:
    print("YES")
else:
    print("NO")