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
# sys.setrecursionlimit(400000)
input=lambda:sys.stdin.readline().strip()
# write=lambda x:sys.stdout.write(str(x)+'\n')

# from decimal import Decimal
# from datetime import datetime,timedelta
# from random import randint
# from copy import deepcopy
from collections import deque,Counter
# from heapq import heapify,heappush,heappop
# from bisect import bisect_left,bisect,insort
from math import inf,sqrt,gcd,pow,ceil,floor,log,log2,log10,pi,sin,cos,tan,asin,acos,atan
# from functools import cmp_to_key,reduce
# from operator import or_,xor,add,mul
# from itertools import permutations,combinations,accumulate

def solve():
    s=input()
    n=len(s)
    seg='';t=0
    for i in range(n-1):
        if s[i:i+2]=='AB' or s[i:i+2]=='BA':
            seg=s[i:i+2]
            t=i+2
            break
    if not seg:
        print('NO')
        return
    seg=seg[::-1]
    for i in range(t,n-1):
        if s[i:i+2]==seg:
            print('YES')
            break
    else:
        print('NO')
    return

# t=int(input())
# for _ in range(t):
#     solve()

solve()