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_left, bisect_right
from collections import Counter, deque
from functools import lru_cache
from math import factorial, comb
import heapq


s = input()
dp = [0] * len(s)
for i in range(1, len(s)):
    if s[i - 1: i + 1] == "AB":
        dp[i] = (1 << 1) | dp[i - 2]
    elif s[i - 1: i + 1] == "BA":
        dp[i] = 1 | dp[i - 2]
    else:
        dp[i] = dp[i - 1]
    if i >= 3:
        dp[i] = dp[i] | dp[i - 3]
# print(dp)
if dp[-1] == 3:
    print("YES")
else:
    print("NO")



