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.
s = input()
s1 = 0
q_AB = 0
q_BA = 0
for j in range(1,len(s)):
    if s1 == 1:
        s1 = 1
    if s1 == 0:
        if s[j] == "A":
            if s[j-1] == "B":
                if s[j-2] != "A":
                    if q_AB > 0:
                        s1 = 1
                    else:
                        s1 = 0
                    q_BA += 1


        elif s[j] == "B":
            if s[j-1] == "A":
                if s[j-2] != "B":
                    if q_BA > 0:
                        s1 = 1
                    else:
                        s1 = 0
                    if s[j-2] != "B":
                        q_AB += 1
        else:
            s1 = 0
if s1 == 1:
    print("YES")
else:
    print("NO")