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;

int main(){
    int X,ct=0,ct1=0,ct2=0;
    string S;
    cin>>S;
    X=S.length();

    for(int i=0; i<X-2; i++){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='A'){
            ct++;
            i=i+2;
        }
        if(S[i]=='B' && S[i+1]=='A' && S[i+2]=='B'){
            ct++;
            i=i+2;
        }
    }
    for(int i=0; i<X-1; i++){
        if(S[i]=='A' && S[i+1]=='B'){
            ct1++;
            i++;
        }
        if(S[i]=='B' && S[i+1]=='A'){
            ct2++;
            i++;
        }
    }

    if(((ct1+ct2)-ct)>=2 && ct1>0 && ct2>0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }




    return 0;
}