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 sys, math, itertools, functools, collections
from collections import Counter

input = lambda: sys.stdin.readline().strip()

MIN = 10 ** 18
MAX = -10 ** 18


def int_j():
    return int(input())


def int_m():
    return map(int, input().split())


def list_m():
    return list(map(int, input().split()))


def occurred_once(arr):
    ans = list()
    mp = Counter(arr)
    for it in mp:
        if mp[it] == 1:
            list.append(it)
            return it
    return ans


def find_sum(num: int):
    if num != 0:
        return num % 10 + find_sum(num // 10)
    else:
        return 0


a = input()

if 'AB' in a and 'BA' in a:
    if 'ABBA' in a or 'BAAB' in a:
        print("NO")
    else:
        print("YES")
else:
    print("NO")
