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 finding(test_str):
    ab = [];
    ba = [];
    i = test_str.find('AB');
    j = test_str.find('BA');

    while True:
        if(i != -1):
            ab.append(i);
            i = test_str.find('AB',i+1);
        elif j != -1:
            ba.append(j);
            j = test_str.find('BA',j+1)
        if(i == -1 and j == -1):
            break;
    try:
        if (ab[0] < ba[0]):
            ba = [i - 1 for i in ba]
        else:
            ab = [i - 1 for i in ab]

        if len(ab) != len(ba):
            return 'YES'
        if len(ab) == 1 and len(ba) == 1 and ba == ab:
            return 'NO'
        else:
            return 'YES'
    except:
        return 'NO';


str = input()
print(finding(str));

# for i in test_str length:
#
