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, io, os
import math
import bisect
import heapq
import string
from collections import defaultdict,Counter,deque
input = sys.stdin.readline
 
def I():
    return input()
 
def II():
    return int(input())
 
def MII():
    return map(int, input().split())
 
def LI():
    return list(input().split())
 
def LII():
    return list(map(int, input().split()))
 
def GMI():
    return map(lambda x: int(x) - 1, input().split())
 
def LGMI():
    return list(map(lambda x: int(x) - 1, input().split()))
 
def WRITE(out):
  return print('\n'.join(map(str, out)))
 
def WS(out):
  return print(' '.join(map(str, out)))
 
def WNS(out):
  return print(''.join(map(str, out)))

def WSNOPRINT(out):
  return ''.join(map(str, out))

'''
'''
def solve():
    d = defaultdict(list)
    s = I().strip()
    for i in range(1, len(s)):
        d[s[i-1]+s[i]].append(i)
    
    ok = False
    if 'AB' in d and 'BA' in d:
        for i in d['AB']:
            for j in d['BA']:
                ok |= abs(i-j) > 1
    print('YES' if ok else 'NO')

solve()