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
from copy import deepcopy
import heapq


s = input()
dp = [0] * len(s)  # 0 什么都不是，-1 任意一个, 1 是"AB", 2 是"BA"
for i in range(1, len(s)):
    if s[i - 1: i + 1] == "AB":
        if dp[i - 2] == -1:
            print("YES")
            break
        elif dp[i - 1] == 2:
            dp[i] = -1
        else:
            dp[i] = 1
    elif s[i - 1: i + 1] == "BA":
        if dp[i - 2] == -1:
            print("YES")
            break
        elif dp[i - 1] == 1:
            dp[i] = -1
        else:
            dp[i] = 2
    else:
        dp[i] = dp[i - 1]
else:
    print("NO")
# print(dp)





