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).

Input

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Output

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

Examples

Input

ABA


Output

NO


Input

BACFAB


Output

YES


Input

AXBYBXA


Output

NO

Note

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".
from collections import Counter
import string
import math
import sys
sys.setrecursionlimit(10**6) 
from fractions import Fraction
def array_int():
    return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
    if arrber_of_variables==1:
        return int(sys.stdin.readline())
    if arrber_of_variables>=2:
        return map(int,sys.stdin.readline().split()) 
def makedict(var):
    return dict(Counter(var))
# i am noob wanted to be better and trying hard for that
def printDivisors(n): 
    divisors=[]  
    # Note that this loop runs till square root 
    i = 1
    while i <= math.sqrt(n): 
          
        if (n % i == 0) : 
              
            # If divisors are equal, print only one 
            if (n//i == i) : 
                divisors.append(i) 
            else : 
                # Otherwise print both 
                divisors.extend((i,n//i)) 
        i = i + 1
    return divisors
 
def countTotalBits(num):
     binary = bin(num)[2:]
     return(len(binary))
def isPrime(n):
    # Corner cases 
    if (n <= 1) : 
        return False
    if (n <= 3) : 
        return True
  
    # This is checked so that we can skip  
    # middle five numbers in below loop 
    if (n % 2 == 0 or n % 3 == 0) : 
        return False
  
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
  
    return True
mod=10**9+7
def ncr(n,r):
    if n<r:
        return 0
    if n==r:
        return 1
    numer=fact[n]
    # print(numer)
    denm=(fact[n-r]*fact[r])
    # print(denm)
    return numer*pow(denm,mod-2,mod)
# def dfs(node):
#     global graph,color_in,ans,visited
#     visited[node]=1
#     col=color_in[node]
#     for i in graph[node]:
#         if visited[i]==0:
#             if col!=color_in[i]:
#                 ans+=1
fact=[1]*(1001)
c=1 
mod=10**9+7
for i in range(1,1001):
    fact[i]=(fact[i-1]*i)%mod
# print(fact)
def comp(x):
    return x[1]
def binary_search(arr, x): 
    low = 0
    high = len(arr) - 1
    mid = 0
  
    while low <= high: 
  
        mid = (high + low) // 2
  
        # Check if x is present at mid 
        if arr[mid] < x: 
            low = mid + 1
  
        # If x is greater, ignore left half 
        elif arr[mid] > x: 
            high = mid - 1
  
        # If x is smaller, ignore right half 
        else: 
            return mid 
  
    # If we reach here, then the element was not present 
    return -1
s=input()
# print(s.count('AB'))
if 0:
    pass
else:
    if 0:
        pass
    else:
        if s.count('BA')==0 or s.count('AB')==0:
            print('NO')
        elif s.count('AB')==2 and s.count('BA')==1:
            if s[s.find('AB')+2:s.find('AB')+4]=='AB':
                print('NO')
            else:
                print('YES')
        elif s.count('BA')==2 and s.count('AB')==1:
            if s[s.find('BA')+2:s.find('BA')+4]=='BA':
                print('NO')
            else:
                print('YES')
        else:
            if s.count('AB')==1 and s.count('BA')==1 and (s.find('AB')<s.find('BA')):
                # if s.find('AB')<s.find('BA'):
                if s.find('AB')+1==s.find('BA'):
                    print('NO')
                else:
                    print('YES')
            elif s.count('BA')==1 and s.count('AB')==1:
                if s.find('BA')+1==s.find('AB'):
                    print('NO')
                else:
                    print('YES')
            else:
                print('YES')
    
    

    


