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.
'''string=str(input())
substrings = [string[i: j] for i in range(len(string))
          for j in range(i + 1, len(string) + 1)]
print(substrings)
for i in substrings:
  if i=="AB":
    index=substrings.index(i)
    break
print(index)
'''
string = str(input())
foundAB = False
foundBA = False
stopSearch = False
for i in range(len(string) - 1):
    if stopSearch == False:
        if (string[i] == 'A' and string[i + 1] == 'B') and not foundAB:
            foundAB = True
            stopSearch = True
        elif (string[i] == 'B' and string[i + 1] == 'A') and not foundBA:
            foundBA = True
            stopSearch = True
        
        else:
            stopSearch = False
    else:
        stopSearch = False

if foundAB and foundBA:
    print("YES")
else:
    print("NO")