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 heapq import heapify,heappop,heappush
from queue import deque
from collections import defaultdict
import math

def I(): return int(input())
def ST(): return input()
def IL(): return list(map(int, input().split()))
def ILS(): return sorted(map(int, input().split()))
def STL(): return list(input())

def checker(word,chrs):
    ind,length = 0,len(word)
    while ind < length:
        temp = ind
        while ind < length and word[ind:ind+2] == chrs:
            ind += 2
        if temp != ind and ind < length:
            if word[ind] == chrs[0] and word[temp-1] != chrs[1]:  
                return False
        ind += 1
    return True

def solve():
    word = ST()
    if "AB" in word and "BA" in word:
        if checker(word,"AB") and checker(word,"BA"):
            return "YES"
    return "NO"
       
T = 1
# T = I()
for _ in range(T):
    print(solve())