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
from math import *
# from pprint import pprint as pprint
# from sympy.ntheory.modular import crt
import heapq
from copy import *
from collections import *
import functools
from itertools import *
from math import sqrt, ceil
import threading
import cmath
import time
import re
# fin = sys.stdin.read().strip()

def solve():
    s = input()
    ab = []
    ba = []
    for i in range(len(s) - 1):
        if s[i] == 'A' and s[i + 1] == 'B':
            ab.append(i)
        elif s[i] == 'B' and s[i + 1] == 'A':
            ba.append(i)
    if not ab or not ba:
        print("NO")
        return

    if abs(ab[0] - ba[-1]) > 1 or abs(ab[-1] - ba[0]) > 1:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    # t = int(input())
    # for _ in range(t):
    #     solve()
    solve()
