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 heapq 
from collections import defaultdict 
import math 
import collections



mod=10**9+7
alp='#abcdefghijklmnopqrstuvwxyz'
cap='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digit='1234567890'



#math.facorial(n)------>gives the factorial 






for _ in range(1):
    
    #n =int(input()) 
    #n , m =map(int,input().split())
    #l=list(map(int,input().split()))
    s=input()
    l=['AB','BA']
    f1=0 
    f2=0 
    f3=0 
    f4=0 
    n =len(s)
    i=0 
    tar=0 
    while(i<n-1):
        if s[i]==l[tar][0] and s[i+1]==l[tar][1]:
            tar+=1 
            i+=2 
        else:
            i+=1 
        if tar>1:
            f1=1 
    i=0 
    tar=1 
    while(i<n-1):
        if s[i]==l[tar][0] and s[i+1]==l[tar][1]:
            tar-=1
            i+=2 
        else:
            i+=1 
        if tar<0:
            f2=1 
    if f1 or f2:
        print("YES")
    else:
        print("NO")
            
        