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 has_non_overlapping_substrings(s):
    # Initialize two sets to keep track of the occurrences of 'AB' and 'BA'
    ab_occurrences = set()
    ba_occurrences = set()
    
    # Iterate through the string s and keep track of the current letter
    for i in range(len(s)):
        # If the current letter is 'A', add it to either 'ab_occurrings' or 'ba_occurrences' depending on its position
        if s[i] == 'A':
            if i < len(s) - 1 and s[i + 1] == 'B':
                ab_occurrences.add(i)
            elif i < len(s) - 1 and s[i + 1] == 'A':
                ba_occurrences.add(i)
    # Check if there are any common elements between 'ab_occurrences' and 'ba_occurrences'
    if len(ab_occurrences.intersection(ba_occurrences)) > 0:
        return "YES"
    else:
        return "NO"

s = input().strip()
print(has_non_overlapping_substrings(s))