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
int main(){
    string s;
    cin>>s;
    ll n=s.length();
    bool f1=false,f2=false;
    ll a=0,b=0;
    for(ll i=0;i<n-1;i+=2){
        if(s[i]=='B' && s[i+1]=='A'){
            f1=true;
            a=i;
            break;
        }
    }
    for(ll i=0;i<n-1;i+=2){
        if(s[i]=='A' && s[i+1]=='B'){
            f2=true;
            b=i;
            break;
        }
    }
    if(f1 && f2 && a!=b){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}
 				  		 	  	       	  	  	  	