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

in_f = sys.stdin.read(-1).replace("\r\n", "\r")
in_f = in_f.split()[0]
n = len(in_f)

index1 = 0
index2 = 2
found_dict = {"AB": False, "BA": False}
while index2 <= n:
    substring = in_f[index1:index2]
    if substring == "AB" or substring == "BA":
        found_dict[substring] = True
        index1 += 2
        index2 += 2
    index1 += 1
    index2 += 1
if found_dict["AB"] and found_dict["BA"]:
    print("YES")
else:
    print("NO")
