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.
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 13 18:26:09 2022

@author: ltimp
"""

import numpy as np

s = input()
n = len(s)
i = 0
l = []
while i < n:
    if s[i] not in ("A", "B"):
        i += 1
        continue
    j = 0
    while i + j < n and s[i + j] in ("A", "B"):
        j += 1
    l.append(s[i:i+j+1])
    i += j + 1
ab = l.copy()
ba = l.copy()
for i in range(len(l)):
    ab[i] = "AB" in l[i]
    ba[i] = "BA" in l[i]
ab = np.array(ab)
ba = np.array(ba)
tt = np.sum(ab & ba)
tf = np.sum(ab & np.logical_not(ba))
ft = np.sum(ba & np.logical_not(ab))
# print(tt, tf, ft)
if tt > 1 or (tf > 0 and ft > 0) or (tt > 0 and (tf > 0 or ft > 0)):
    print("YES")
else:
    print("NO")