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 contains_non_overlapping_AB_BA(s):
    # Find the first occurrence of "AB" in the string
    first_ab_index = s.find("AB")

    # If "AB" is found, search for "BA" after the end of "AB" (if it exists)
    if first_ab_index != -1:
        remaining_string = s[first_ab_index + 2:]
        second_ba_index = remaining_string.find("BA")

        # If "BA" is found and it starts after the end of the first "AB," return "YES"
        if second_ba_index != -1:
            return "YES"

    # Repeat the process for "BA" followed by "AB"
    first_ba_index = s.find("BA")
    if first_ba_index != -1:
        remaining_string = s[first_ba_index + 2:]
        second_ab_index = remaining_string.find("AB")
        if second_ab_index != -1:
            return "YES"

    # If none of the conditions are met, return "NO"
    return "NO"

# Input string from the user
s = input("Enter a string: ")

result = contains_non_overlapping_AB_BA(s)
print(result)
