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)

i = 0
found_dict = {"AB": 0, "BA": 0}
overlap_count = 0
while i < n:
    substring = in_f[i:i+3]
    if substring == "ABA" or substring == "BAB":
        found_dict["AB"] += 1
        found_dict["BA"] += 1
        overlap_count += 1
        i += 2
    elif "AB" in substring:
        found_dict["AB"] += 1
        i += 2
    elif "BA" in substring:
        found_dict["BA"] += 1
        i += 2
    else:
        i += 1
while overlap_count != 0:
    if found_dict["AB"] > found_dict["BA"]:
        found_dict["AB"] -= 1
    else:
        found_dict["BA"] -= 1
    overlap_count -= 1
if found_dict["AB"] > 0 and found_dict["BA"] > 0:
    print("YES")
else:
    print("NO")
