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=[]
    for   i in range(n):
        l1=list(map(int,input().split()))
        l.append(l1)'''
    #print(math.gcd(-2,-6))
    #l=list(map(int,input().split()))
    s=input()
    n =len(s)
    f=0
    for i in range(0,n-1):
        if s[i]=='A' and s[i+1]=='B':
           
            f=1
            s1=s[0:i]
            s2=""
            if i+2<=n-2:
                s2=s[i+2::]
    
    if f==0:
        print("NO")
    else:
        n1=len(s1)
        n2=len(s2)
        for i  in range(0,n1-1):
            if s1[i]=='B' and s1[i+1]=='A':
                f=0 
        for i  in range(0,n2-1):
            if s2[i]=='B' and s2[i+1]=='A':
                f=0 
        if f==0:
            print("YES")
        else:
            print("YES")
        
            
    
        