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, threading
input = sys.stdin.readline
from collections import defaultdict
input = sys.stdin.readline

def main():
    s = input().strip()
    # A = set()
    # B = set()
    n= len(s)
    cur = None
    found = []
    look_for = ["AB", "BA"]
    last_AB = []
    last_BA = []
    for i in range(n-1):
        if s[i]+s[i+1] in "AB":
            last_AB.append(i)
            if last_BA and last_BA[0] != i-1:
                print("YES")
                break
        elif s[i]+s[i+1] in "BA":
            last_BA.append(i)
            if last_AB and last_AB[0] != i-1:
                print("YES")
                break
    else:
        print("NO")

    

    
    




# Set the stack size
threading.stack_size(1 << 27)

# Create and start the main thread
main_thread = threading.Thread(target=main)
main_thread.start()

# Wait for the main thread to complete
main_thread.join()
