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.
from itertools import combinations
from collections import Counter;
def findingallaccurance(test_str):
    i =0;
    f = 0;
    outi = 0;
    outf = 0;
    for j in range(len(test_str)):
        if(f >= len(test_str) or i >= len(test_str)):
            break;
        if(outi+ outf == 2):
            break;

        i =test_str.find('AB',i);
        f = test_str.find('BA',f);
        if f != i +1:
            if i != -1:
                outi += 1;
            elif f != -1:
                outf += 1;

    return 'YES' if outf + outi >= 2  else "NO";

str = input()
print(findingallaccurance(str))