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.
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main(){
    string s;
    cin>>s;
    int n = s.size();
    int ab=0,ba=0;
    bool a=true,b=true;
    for(int i=0;i<n-1;i++){
        if(s[i]=='A' && s[i+1]=='B'){
            ab++;
            if(a){
                i++;
                a=false;
            }
        }
        else if(s[i]=='B' && s[i+1]=='A'){
            ba++;
            if(b){
                i++;
                b=false;
            }
        }
    }
    if(ab>=1 && ba>=1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}