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 = "ABCBA"


def solve(s):
    i = 0
    ba = False
    ab = False

    while i < len(s) - 1:
        if not ba and s[i] == 'B' and s[i + 1] == 'A':
            ba = True
            i += 2
            continue

        if not ab and s[i] == 'A' and s[i + 1] == 'B':
            ab = True
            i += 2
            continue

        i += 1

    if ab and ba:
        print("YES")
    else:
        print("NO")


def find_ab(s):
    i = 0
    while i < len(s) - 1:
        if s[i] == 'A' and s[i + 1] == 'B':
            return i
        i += 1
    return -1


def find_ba(s):
    i = 0
    while i < len(s) - 1:
        if s[i] == 'B' and s[i + 1] == 'A':
            return i
        i += 1
    return -1


def _solve(s):
    idx1 = find_ab(s)
    if idx1 == -1:
        res1 = -1
    else:
        res1 = find_ba(s[idx1 + 2:])

    idx2 = find_ba(s)

    if idx2 == -1:
        res2 = -1
    else:
        res2 = find_ab(s[idx2 + 2:])

    if res1 == -1 and res2 == -1:
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    s = input()
    _solve(s)


