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.
def substring():
    x = input()
    y = "AB"
    count = 0
    num = False
    i = 0
    while i != len(y)-1:
        if (x[i] == "A" and x[i + 1] == "B") or (x[i] == "B" and x[i + 1] == "A"):
            break
        else:
            count += 1
        i += 1

    y = list(x.lstrip(x[count:count + 2]))
    j = 0
    if len(y)!=0:
        while j != len(y)-1:

            if (y[j] == "A" and y[j + 1] == "B") or (y[j] == "B" and y[j + 1] == "A"):
                num = True
                break
            j += 1

    if num == False:
        print("NO")
    else:
        print("YES")


substring()