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):
    out = [-1,-1];
    text = [0,0];
    i = 0;
    j = 0;
    while out[0] == -1 and out[1] == -1:
        i = test_str.find('AB',i);
        j = test_str.find('BA',j);
        if i+1 != text[1] and j+1 != text[0] and i != -1 and out[0] == -1:
            out[0] = 1;
            text[0] = i;
        elif i+1 != text[1] and j+1 != text[0] and j != -1 and out[1] == -1:
            out[1] = 1;
        else:
            return 'NO';
    return 'YES';


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

# for i in test_str length:
#

