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)
    for i in range(n-1):
        if s[i] == 'A' and s[i+1] == 'B':
            A.add(i)
            B.add(i+1)
    for i in range(n-1):
        if i+1 not in A and s[i] == 'B' and s[i+1] == 'A' and i not in B:
            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()
