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 main():
    s = input()
    s1 = str(s.split('ABA'))

    ab = 0
    ba = 0
    AB = []
    BA = []
    for i in range(1, len(s)):
        if s[i-1] == 'A' and s[i] == 'B':
            ab += 1
            AB.append({i-1, i})
        if s[i-1] == 'B' and s[i] == 'A':
            ba += 1
            BA.append({i - 1, i})

    if len(AB) == 0 or len(BA) == 0:
        print('NO')
        return

    c = 0
    for i in BA:
        for j in AB:
            if len(i & j) == 0:
                c += 1
    if c > 0:
        print('YES')
    else:
        print('NO')


main()


