#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define OO 4e18
#define oo 2e9
#define yalla ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define sz  100005
#define re return
#define F first
#define S second
#define pll pair<ll,ll>
#define mod  1000000007
#define pi acos(-1)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
string s,tmp,tmp2;
vector<string>ans;
int ok,last=-1;
///
int main()
{
    yalla;
    while(getline(cin,s))
    {int nott=0,done=0;
     tmp2="";
     ///
     for(int i=0;i<s.size();i++)
     { if(s[i]=='#'&&!nott)
       {
        done=1; break;
       }
       else if(s[i]!=' ')
       {
         nott=1;
         tmp+=s[i];
       }
       else tmp2+=s[i];
     }
     ///
     if(s.empty()||(!nott&&!done) )
       last=0;
     else if(done)
     {   if(last==0)ok=1;
         if(tmp.size()) ans.push_back(tmp),ok=0;
         else if(ok) ans.push_back(""),ok=0;

         ans.push_back(s);

        tmp=tmp2="";
        last=1;
     }
     else last=2;
    }
    ///
    if(tmp.size()) ans.push_back(tmp);
    else if(!last) ans.push_back("");
    for(int i=0;i<ans.size();i++)
      cout<<ans[i]<<endl;

    re 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define OO 4e18
#define oo 2e9
#define yalla ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define sz  100005
#define re return
#define F first
#define S second
#define pll pair<ll,ll>
#define mod  1000000007
#define pi acos(-1)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
string s,tmp,tmp2;
vector<string>ans;
int ok,last=-1;
///
int main()
{
    yalla;
    while(getline(cin,s)&&s[0]!='-')
    {int nott=0,done=0;
    tmp2="";
     ///
     for(int i=0;i<s.size();i++)
     { if(s[i]=='#'&&!nott)
       {
        done=1; break;
       }
       else if(s[i]!=' ')
       {
         nott=1;
         tmp+=s[i];
       }
       else tmp2+=s[i];
     }
     ///
     if(s.empty()||(!nott&&!done) )
     { if(last!=2)ok=1;
       last=0;
     }
     else if(done)
     {   if(last==0)ok=1;
         if(tmp.size()) ans.push_back(tmp),ok=0;
         else if(ok) ans.push_back(tmp2),ok=0;

         ans.push_back(s);

        tmp=tmp2="";
        last=1;
     }
     else last=2;
    }
    ///
    if(tmp.size()) ans.push_back(tmp),ok=0;
    if(ok)ans.push_back(tmp2);
    for(int i=0;i<ans.size();i++)
      cout<<ans[i]<<endl;

    re 0;
}


#include<stdio.h>
#include<string.h>
char s[1000010];
int len;
int main()
{
    int i=0,k;
    while(gets(s)!=NULL)
    {
        len=strlen(s);
        int flag = 1;
        for(k=0;k<len;k++)
        {
            if(s[k]=='#')
            {
                for(int h=0;h<k;h++)
                {
                    if(s[h]!=' ')
                        flag=0;
                }
                break;
            }
        }
        if(k != len && flag == 1 && i)
            puts("");
        if(k != len && flag == 1)
            puts(s);
        else
        {
            for(k=0;k<len;k++)
            {
                if(s[k]==' ')
                    continue;
                printf("%c",s[k]);
            }
        }
        i++;
    }
    puts("");
    return 0;
}


#include<stdio.h>
#include<string.h>
char s[1000010];
int len;
int main()
{
    int i=0,k,flag;
    while(gets(s)!=NULL)
    {
        len=strlen(s);
        flag = 1;
        for(k=0;k<len;k++)
        {
            if(s[k]=='#')
            {
                for(int h=0;h<k;h++)
                {
                    if(s[h]!=' ')
                        flag=0;
                }
                break;
            }
        }
        if(k==len)
            flag=0;
        if(k != len && flag == 1 && i)
            puts("");
        if(k != len && flag == 1)
            puts(s);
        else
        {
            for(k=0;k<len;k++)
            {
                if(s[k]==' ')
                    continue;
                printf("%c",s[k]);
            }
        }
        i++;
    }
    if(!flag)
        puts("");
    return 0;
}


#include<stdio.h>
#include<string.h>
char s[1000010];
int len;
int main()
{
    int i=0,k,flag;
    while(gets(s)!=NULL)
    {
        len=strlen(s);
        flag = 1;
        for(k=0;k<len;k++)
        {
            if(s[k]=='#')
            {
                for(int h=0;h<k;h++)
                {
                    if(s[h]!=' ')
                        flag=0;
                }
                break;
            }
        }
        if(k != len && flag == 1 && i)
            puts("");
        if(k != len && flag == 1)
            puts(s);
        else
        {
            for(k=0;k<len;k++)
            {
                if(s[k]==' ')
                    continue;
                printf("%c",s[k]);
            }
        }
        i++;
    }
    if(!flag)
        puts("");
    return 0;
}


#include<stdio.h>
#include<string.h>
char s[1000010];
int len;
int main()
{
    int i=0,j,k;
    while(gets(s)!=NULL)
    {
        len=strlen(s);
        int flag = 1;
        for(k=0;k<len;k++)
        {
            if(s[k]=='#')
            {
                for(int h=0;h<k;h++)
                {
                    if(s[h]!=' ')
                        flag=0;
                }
                break;
            }
        }
        if(k != len && flag == 1)
            puts(s);
        else
        {
            for(k=0;k<len;k++)
            {
                if(s[k]==' '||s[k]=='\n')
                    continue;
                printf("%c",s[k]);
            }
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
using namespace std;

const int N = 40000100;
char s[N];
char buffer[N];

int main()
{
    int mark=1;
    int now=0;
    while (gets(s))
    {
        now=0;
        for (int i=0;s[i];++i)
        {
            if (s[i]!=' ')
            {
                if (s[i]=='#')
                {
                    now=1;
                }
                else
                {
                    break;
                }
            }
        }
        if(now)
        {
            if(!mark)
            {
                puts("");
            }
            puts(s);
            mark=1;
        }
        else
        {
            for(int i=0;s[i];i++)
            {
                if (s[i]!=' ')
                {
                    putchar(s[i]);
                }
            }
            mark=0;
        }
    }
    if (!mark)
    {
        puts("");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define NMAX 500005
const long double PI = acos(-1);

char s[1148576];
string cnt;
int hs = 0;

int main(){
  ios::sync_with_stdio(false);
  while (cin.getline(s,1148573)){
  	int n = strlen(s);
  	int ok = 0;
  	for (int i=0;i<n;i++){
  		if (s[i] == '#'){
  			ok = 1;
  		}
  		if (s[i] != ' '){
  			break;
  		}
  	}
  	if (!ok){
  		hs = 1;
  		for (int i=0;i<n;i++){
  			if (s[i] != ' '){
  				cnt += s[i];
  			}
  		}
  	}
  	else{
  		if (hs){
  			cout << cnt << '\n';
  		}
  		cout << s << '\n';
  		hs = 0;
  		cnt.clear();
  	}
  }
  if (hs){
  	cout << cnt << '\n';
  }
  return 0;
}


#include <algorithm>
#include <array>
#include <iostream>
#include <limits>
#include <numeric>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::string line;
  std::string acc;
  bool simple = false;
  while(std::getline(std::cin, line)){
    bool power = false;
    for(char c: line){
      if(c == ' '){
        continue;
      }
      if(c == '#'){
        power = true;
      }
      break;
    }
    if(power){
      if(simple){
        std::cout << acc << '\n';
        acc.clear();
      }
      std::cout << line << '\n';
      simple = false;
    }else{
      for(char c: line){
        if(c != ' '){
          acc += c;
        }
      }
      simple = true;
    }
  }
  if(simple){
    std::cout << acc << '\n';
  }
}


#include<iostream>
using namespace std;
int main()
{
int i,k=0;
string s;
while(getline(cin,s))
{
for(i=0;i<s.length();i++) if(s[i]!=' ') break;
if(i==s.length() || s[i]!='#')
{
if(k==2) cout<<endl;
for(i=0;i<s.length();i++) if(s[i]!=' ') cout<<s[i];
k=1;
}
else
{
if(k) cout<<endl;
cout<<s;
k=2;
}
}
cout<<endl;
return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iterator>

#define x0 abc
#define y0 ABC
#define x1 abcd
#define y1 ABCD
#define xn abcde
#define yn ABCDE

#define l_b lower_bound
#define u_b upper_bound

#define in insert
#define er erase

#define fi first
#define se second
#define m_p make_pair

#define p_b push_back
#define po_b pop_back

#define uns unsigned

#define ld long double
#define ll long long

#define cont continue
#define re return

#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000

#define MINLL -9000000000000000000LL
#define MININT -2000000000

#define pi acos(-1.)

#define endl '\n'

#define OUT cout << "-------" << endl;

using namespace std;

string s, s1;

int i, kol;

bool x;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    while (getline(cin, s)) {
        x = false;

        for (i = 0; i < s.size(); i++)
            if (s[i] != ' ') {
                if (s[i] == '#')
                x = true;

                break;
            }

        if (x) {
            if (kol > 0)
            cout << s1 << endl;

            cout << s << endl;

            s1 = "";

            kol = 0;

            cont;
        }

        kol++;

        for (i = 0; i < s.size(); i++)
            if (s[i] != ' ') s1 += s[i];
    }

    if (kol > 0)
    cout << s1 << endl;

    re 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iterator>

#define x0 abc
#define y0 ABC
#define x1 abcd
#define y1 ABCD
#define xn abcde
#define yn ABCDE

#define l_b lower_bound
#define u_b upper_bound

#define in insert
#define er erase

#define fi first
#define se second
#define m_p make_pair

#define p_b push_back
#define po_b pop_back

#define uns unsigned

#define ld long double
#define ll long long

#define cont continue
#define re return

#define MAXLL 9000000000000000000LL
#define MAXINT 2000000000

#define MINLL -9000000000000000000LL
#define MININT -2000000000

#define pi acos(-1.)

#define endl '\n'

#define OUT cout << "-------" << endl;

using namespace std;

string s, s1;

int i, kol;

bool x;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    while (getline(cin, s)) {
        x = false;

        for (i = 0; i < s.size(); i++)
            if (s[i] != ' ') {
                if (s[i] == '#')
                x = true;

                break;
            }

        if (x) {
            if (kol > 0)
            cout << s1 << endl;

            cout << s << endl;

            s1 = "";

            kol = 0;

            cont;
        }

        kol++;

        for (i = 0; i < s.size(); i++)
            if (s[i] != ' ') s1 += s[i];
    }

    if (kol > 0)
    cout << s1 << endl;

    re 0;
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    short counter=0;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(0,length)
    {
        if(s[i]=='A'&&s[i+1]=='B')
            {
                counter++;
                s.erase(i,2);
            }
        if(s[i]=='B'&&s[i+1]=='A')
            {
                counter++;
                s.erase(i, 2);
            }

    }

    if(counter>1)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    int A=0,B=0;
    string s;
    cin >> s;

    if(s.find("AB") <= s.length())
        {
             if(s[s.find("AB")+2]=='A')
                 s[s.find("AB")]='c';
             else
                A++;
        }
    if(s.find("BA") <= s.length())
        {
        if(s[s.find("BA")+2]=='B')
           s[s.find("BA")]='c';
        else
            B++;
        }
   if(s.find("AB") <= s.length())
        {
             if(s[s.find("AB")+2]=='A');
             else
                A++;
        }
    if(s.find("BA") <= s.length())
        {
        if(s[s.find("BA")+2]=='B');
        else
            B++;
        }

    if(A>0&&B>0)
            cout << "YES";
        else
            cout << "NO";

}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    short counter=0;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(0,length)
    {
        if(s[i]=='A'&&s[i+1]=='B')
            {
                counter++;
                s.erase(i,2);
            }
        if(s[i]=='B'&&s[i+1]=='A')
            {
                counter++;
                s.erase(i, 2);
            }

    }

    if(counter>2)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,ABA=0,BAB=0;
    string s;
    cin >> s;

    if(s.find("ABA")<=s.length())
    {
        ABA++;
        s[s.find("ABA")+1]='s';
        s[s.find("ABA")+2]='s';
    }

    if(s.find("BAB")<=s.length())
    {
        BAB++;
         s[s.find("BAB")+1]='s';
        s[s.find("BAB")+2]='s';
    }
    if(s.find("AB")<=s.length()&&s[s.find("AB")+2]!='A'&&s[s.find("AB")-1]!='A')
        AB++;
    if(s.find("BA")<=s.length()&&s[s.find("BA")+2]!='B'&&s[s.find("AB")-1]!='A')
        BA++;

if(AB>0&&BA>0)
    cout << "YES";
    else if(AB==0&&BA>0&&ABA>0)
        cout << "YES";
    else if(BA==0&&AB>0&&BAB>0)
        cout << "YES";
    else
        cout << "NO";

}

    /*

    if(s.find("AB") <= s.length())
        {
             if(s[s.find("AB")+2]=='A')
                 s[s.find("AB")+2]='c';
             else
                A++;
        }
    if(s.find("BA") <= s.length())
        {
        if(s[s.find("BA")+2]=='B')
           s[s.find("BA")]='c';
        else
            B++;
        }
    if(s.find("BA") <= s.length())
        {
        if(s[s.find("BA")+2]=='B');
        else
            B++;
        }

   if(s.find("AB") <= s.length())
        {
             if(s[s.find("AB")+2]=='A');
             else
                A++;
        }

    if(A>0&&B>0)
            cout << "YES";
        else
            cout << "NO";

}

    /*
    int e=0;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B' )
            {
                if(a==false)
                {
                    a=true;
                    s[i]='c';

                }
                else
                    e++;
            }
        if(s[i]=='B'&&s[i-1]=='A' )
            {
               if(b==false)
                {
                    b=true;
                    s[i]='c';

                }
                else
                    e++;
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else if(e>0)
        cout << "YES";
    else
        cout << "NO";
}*/


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;
int c,size;
 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,ABA=0,BAB=0;
    string s;
    cin >> s;

    if(s.find("ABA")<=s.length())
    {
        c=s.find("ABA");
        ABA++;

    }

    if(s.find("BAB")<=s.length())
    {
        BAB++;
       c=s.find("BAB");

     }
     if(s.find("AB")<=s.length() )
        AB++;

    if(s.find("BA")<=s.length() )
        BA++;

   if(AB>0&&BA>0)
    cout << "YES";
    else if(ABA>0&&(AB>0||BA>0))
        cout << "YES";
     else if(BAB>0&&(AB>0||BA>0))
            cout << "YES";
    else if(ABA>0&&BAB>0)
        cout << "YES";
    else
        cout << "NO";

}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;
int c,size;
 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,ABA=0,BAB=0;
    string s;
    cin >> s;

    AB = s.find("AB");
    ABA = s.find("ABA");
    BAB = s.find("BAB");
    BA = s.find("BA");

   if(AB<s.length()&&BA<s.length())
   {
       if(AB+1!=BA&&BA+1!=AB)
        {
            cout << "YES";
            return 0;
        }

    else if(AB<BA)
            s[AB+1]='W';
    else
            s[BA+1]='W';
   }
    AB = s.find("AB");
    ABA = s.find("ABA");
    BAB = s.find("BAB");
    BA = s.find("BA");

   if(AB<s.length()&&BA<s.length())
   {
        if(AB+1!=BA&&BA+1!=AB)
        {
            cout << "YES";
            return 0;
        }

        else if(AB<BA)
            s[AB+1]='W';
        else
            s[BA+1]='W';
   }
   cout << "NO";
}


    #include <bits/stdc++.h>
    #define  loop(n,m) for(int i=n;i<m;i++)
    typedef unsigned long long u32;
    typedef signed long long s32;
    using namespace std;

    int main()
    {
         ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        short counter=0;
        string s;
        long long length;
        cin >> s;
        length = s.length();
        if(length<4)
        {
            cout <<"NO";
            return 0;
        }
        loop(0,length)
        {
            if(s[i]=='A'&&s[i+1]=='B')
                {
                    counter++;
                    s.erase(i,2);
                }
            if(s[i]=='B'&&s[i+1]=='A')
                {
                    counter++;
                    s.erase(i, 2);
                }

        }

        if(counter>=2)
            cout << "YES";
        else
            cout << "NO";
     }


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;
int c,size;
 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,size,i;
    string s;
    cin >> s;
    size = s.length();
    for( i=size-1;i>0;i--)
    {
        if(s[i]=='B'&&s[i-1]=='A'&&AB<1)
        {
            AB++;
            s[i-1]='s';
        }
        else if(s[i]=='A'&&s[i-1]=='B'&&BA<1)
        {
            BA++;
            s[i-1]='s';
        }
    }
    if(AB>0&&BA>0)
        cout <<"YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;
int c,size;
 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,ABA=0,BAB=0;
    string s;
    cin >> s;

    if(s.find("ABA")<=s.length())
    {
        c=s.find("ABA");
        ABA++;
        s[c]='s';
        s[c+1]='s';
        s[c+2]='s';
    }

    if(s.find("BAB")<=s.length())
    {
        BAB++;
       c=s.find("BAB");
        s[c]='s';
        s[c+1]='s';
        s[c+2]='s';
     }
     if(s.find("AB")<=s.length() )
        AB++;

    if(s.find("BA")<=s.length() )
        BA++;

   if(AB>0&&BA>0)
    cout << "YES";
    else if(ABA>0&&(AB>0||BA>0))
        cout << "YES";
     else if(BAB>0&&(AB>0||BA>0))
            cout << "YES";
    else if(ABA>0&&BAB>0)
        cout << "YES";
    else
        cout << "NO";

}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    short counter=0;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(0,length)
    {
        if(s[i]=='A'&&s[i+1]=='B')
            {
                counter++;
                s.erase(i,2);
            }
        if(s[i]=='B'&&s[i+1]=='A')
            {
                counter++;
                s.erase(i, 2);
            }

    }

    if(counter>=2)
        cout << "YES";
    else
        cout << "NO";
 }


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,ABA=0,BAB=0;
    string s;
    cin >> s;

    if(s.find("ABA")<=s.length())
    {
        ABA++;
        s[s.find("ABA")+1]='s';
        s[s.find("ABA")+2]='s';
    }

    if(s.find("BAB")<=s.length())
    {
        BAB++;
         s[s.find("BAB")+1]='s';
        s[s.find("BAB")+2]='s';
    }
    if(s.find("AB")<=s.length()&&s[s.find("AB")+2]!='A'&&s[s.find("AB")-1]!='A')
        AB++;
    if(s.find("BA")<=s.length()&&s[s.find("BA")+2]!='B'&&s[s.find("AB")-1]!='A')
        BA++;

if(AB>0&&BA>0)
    cout << "YES";
    else if(AB==0&&BA>0&&ABA>0)
        cout << "YES";
    else if(BA==0&&AB>0&&BAB>0)
        cout << "YES";
    else if(ABA>0&&BAB>0)
        cout << "YES";
    else
        cout << "NO";

}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B')
            {
                a=true;
                s[i]='c';
                s[i]='w';
            }
        if(s[i]=='B'&&s[i-1]=='A')
            {
                b=true;

                s[i]='c';
                s[i]='w';
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;
int c,size;
 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,size,i;
    string s;
    cin >> s;
    size = s.length();
    for( i=size;i>0;i--)
    {
        if(s[i]=='B'&&s[i-1]=='A')
        {
            AB++;
            s[i-1]='s';
        }
        else if(s[i]=='A'&&s[i-1]=='B')
        {
            BA++;
            s[i-1]='s';
        }
    }
    if(AB>0&&BA>0)
        cout <<"YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B')
            {
                a=true;
                s.erase(i,2);
            }
        if(s[i]=='B'&&s[i-1]=='A')
            {
                b=true;
                s.erase(i, 2);
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B'&&a==false)
            {
                a=true;
                s[i]='c';
                s[i-1]='w';
            }
        if(s[i]=='B'&&s[i-1]=='A'&&b==false)
            {
                b=true;

                s[i]='c';
                s[i-1]='w';
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    string s;
    int e=0;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B' )
            {
                if(a==false)
                {
                    a=true;
                    s[i]='c';
                    s[i-1]='w';
                }
                else
                    e++;
            }
        if(s[i]=='B'&&s[i-1]=='A' )
            {
               if(b==false)
                {
                    b=true;
                    s[i]='c';
                    s[i-1]='w';
                }
                else
                    e++;
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else if(e>0)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;
int c,size;
 int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int AB=0,BA=0,ABA=0,BAB=0;
    string s;
    cin >> s;

    if(s.find("ABA")<=s.length())
    {
        c=s.find("ABA");
        ABA++;
        s[c]='s';
        s[c+1]='s';
        s[c+2]='s';
    }

    if(s.find("BAB")<=s.length())
    {
        BAB++;
       c=s.find("BAB");
        s[c]='s';
        s[c+1]='s';
        s[c+2]='s';
     }

    if(s.find("AB")<=s.length()&&s[s.find("AB")+2]!='A'&&s[s.find("AB")-1]!='A')
        AB++;

    if(s.find("BA")<=s.length()&&s[s.find("BA")+2]!='B'&&s[s.find("AB")-1]!='A')
        BA++;

   if(AB>0&&BA>0)
    cout << "YES";
    else if(ABA>0&&(AB>0||BA>0))
        cout << "YES";
     else if(BAB>0&&(AB>0||BA>0))
            cout << "YES";
    else if(ABA>0&&BAB>0)
        cout << "YES";
    else
        cout << "NO";

}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B')
            {
                a=true;
                s[i]='c';
                s[i-1]='w';
            }
        if(s[i]=='B'&&s[i-1]=='A')
            {
                b=true;

                s[i]='c';
                s[i-1]='w';
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    int count=0;
    string s;
    cin >> s;
   if(s.find("AB") <= s.length())
        {
            s[s.find("AB")+1]='s';
            count++;
        }
    if(s.find("BA") <= s.length())
        {
            s[s.find("BA")+1]='s';
            count++;
        }
        if(s.find("AB") <= s.length())
        {
            s[s.find("AB")+1]='s';
            count++;
        }
    if(s.find("BA") <= s.length())
        {
            s[s.find("BA")+1]='s';
            count++;
        }
        if(count>1)
            cout << "YES";
        else
            cout << "NO";

}

    /*
    int e=0;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B' )
            {
                if(a==false)
                {
                    a=true;
                    s[i]='c';

                }
                else
                    e++;
            }
        if(s[i]=='B'&&s[i-1]=='A' )
            {
               if(b==false)
                {
                    b=true;
                    s[i]='c';

                }
                else
                    e++;
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else if(e>0)
        cout << "YES";
    else
        cout << "NO";
}*/


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    int count=0;
    string s;
    cin >> s;
   if(s.find("AB") <= s.length())
        {
            s[s.find("AB")+1]='s';
            count++;
        }
    if(s.find("BA") <= s.length())
        {
            s[s.find("BA")+1]='s';
            count++;
        }

        if(count>1)
            cout << "YES";
        else
            cout << "NO";

}

    /*
    int e=0;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(1,length)
    {
        if(s[i]=='A'&&s[i-1]=='B' )
            {
                if(a==false)
                {
                    a=true;
                    s[i]='c';

                }
                else
                    e++;
            }
        if(s[i]=='B'&&s[i-1]=='A' )
            {
               if(b==false)
                {
                    b=true;
                    s[i]='c';

                }
                else
                    e++;
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else if(e>0)
        cout << "YES";
    else
        cout << "NO";
}*/


#include <bits/stdc++.h>
#define  loop(n,m) for(int i=n;i<m;i++)
typedef unsigned long long u32;
typedef signed long long s32;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    bool a=false,b=false;
    string s;
    long long length;
    cin >> s;
    length = s.length();
    if(length<4)
    {
        cout <<"NO";
        return 0;
    }
    loop(0,length)
    {
        if(s[i]=='A'&&s[i+1]=='B')
            {
                a=true;
                s.erase(i,2);
            }
        if(s[i]=='B'&&s[i+1]=='A')
            {
                b=true;
                s.erase(i, 2);
            }

    }

    if(a==true&&b==true)
        cout << "YES";
    else
        cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]=='A'&&s[i+1]=='B')l=1,i+=2;
        if (s[i]=='B'&&s[i+1]=='A')r=1,i+=2;
        if (r==1&&l==1) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A') k++,i+=3;
        if (s[i]=='B'&&s[i+1]=='A'&&s[i+2]=='B') k++,i+=3;
        if (s[i]=='A'&&s[i+1]=='B'&&l==0)l=1,i+=2;
        if (s[i]=='B'&&s[i+1]=='A'&&r==0)r=1,i++;
        if ((r==1&&l==1)||(k==1&&(l==1||r==1)||(k>1))) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]=='A'&&s[i+1]=='B')l=1,i++;
        if (s[i]=='B'&&s[i+1]=='A')r=1,i++;
        if (r==1&&l==1) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B' && s[i+1] == 'A' && r==0) r=1, i+=2;
        else if (s[i] == 'A' && s[i+1] == 'B') r=2;
        if (r==2) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B' && s[i+1] == 'A') l++, i+=2;
        else if (s[i] == 'A' && s[i+1] == 'B') r++, i+=2;
        if (r>0&&l>0) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A') k++,i+=3;
        if (s[i]=='A'&&s[i+1]=='B')l=1,i+=2;
        if (s[i]=='B'&&s[i+1]=='A')r=1,i++;
        if ((r==1&&l==1)||(k==1&&(l==1||r==1)||(k>1))) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s[0] == 'B' && s[1] == 'A' && s[s.size()-2] == 'A' && s[s.size()-1] == 'B') {
        cout << "YES";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
        }
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'A' && s[i+3] == 'B') {
                cout << "YES";
                re;
        }
        if (s[i] == 'B' && s[i+1] == 'A' && s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A'&&k<3) k++,i+=3;
        if (s[i]=='A'&&s[i+1]=='B'&&l==0)l=1,i+=2;
        if (s[i]=='B'&&s[i+1]=='A'&&r==0)r=1,i++;
        if ((r==1&&l==1)||(k==1&&(l==1||r==1)||(k>1))) {
            cout << "YES";
            re;
        }
    }
    cout << "NO " << l << " " << r << " " << k;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s[0] == 'B' && s[1] == 'A' && s[s.size()-2] == 'A' && s[s.size()-1] == 'B') {
        cout << "YES";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B' && s[i+1] == 'A') l++, i++;
        else if (s[i] == 'A' && s[i+1] == 'B') r++, i++;
        if (r>0&&l>0) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s[0] == 'B' && s[1] == 'A' && s[s.size()-2] == 'A' && s[s.size()-1] == 'B') {
        cout << "YES";
        re;
    }
    if (s[0] == 'A' && s[1] == 'B' && s[s.size()-2] == 'B' && s[s.size()-1] == 'A') {
        cout << "YES";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
        }
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'A' && s[i+3] == 'B') {
                cout << "YES";
                re;
        }
        if (s[i] == 'B' && s[i+1] == 'A' && s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    if (s[0] == 'B' && s[1] == 'A' && s[s.size()-2] == 'A' && s[s.size()-1] == 'B') {
        cout << "YES";
        re;
    }
    if (s[0] == 'A' && s[1] == 'B' && s[s.size()-2] == 'B' && s[s.size()-1] == 'A') {
        cout << "YES";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A' && s[i+1] == 'B') {
            if (s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
            }
            if (s[i+2] == 'A' && s[i+3] == 'B') {
                cout << "YES";
                re;
            }
        }
        if (s[i] == 'B' && s[i+1] == 'A') {
            if (s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
            }
            if (s[i+2] == 'A' && s[i+3] == 'B') {
                cout << "YES";
                re;
            }
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B' && s[i+1] == 'A') r=1, i+=2;
        else if (s[i] == 'A' && s[i+1] == 'B') r=2;
        if (r==2) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A'&&k<3) k++,i+=3;
        if (s[i]=='A'&&s[i+1]=='B'&&l==0)l=1,i+=2;
        if (s[i]=='B'&&s[i+1]=='A'&&r==0)r=1,i++;
        if ((r==1&&l==1)||(k==1&&(l==1||r==1)||(k>1))) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s[0] == 'B' && s[1] == 'A' && s[s.size()-2] == 'A' && s[s.size()-1] == 'B') {
        cout << "YES";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B' && s[i+1] == 'A' && s[i+2] == 'A' && s[i+3] == 'B') {
                cout << "YES";
                re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B' && s[i+1] == 'A') l++, i+=2;
        if (s[i] == 'A' && s[i+1] == 'B') r++;
        if (r>0&&l>0) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    if (s[0] == 'B' && s[1] == 'A' && s[s.size()-2] == 'A' && s[s.size()-1] == 'B') {
        cout << "YES";
        re;
    }
    if (s[0] == 'A' && s[1] == 'B' && s[s.size()-2] == 'B' && s[s.size()-1] == 'A') {
        cout << "YES";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
        }
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'A' && s[i+3] == 'B') {
                cout << "YES";
                re;
        }
        if (s[i] == 'B' && s[i+1] == 'A' && s[i+2] == 'B' && s[i+3] == 'A') {
                cout << "YES";
                re;
        }
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0

int n, a[N], cnt, sum, l, r, x, y, t, k, m;

ll ans;

string s;

int main () {
    ios_base::sync_with_stdio(false);

    cin >> s;

    if (s.size()<4) {
        cout << "NO";
        re;
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A') k=1,i+=3;
        if (s[i]=='A'&&s[i+1]=='B')l=1,i+=2;
        if (s[i]=='B'&&s[i+1]=='A')r=1,i+=2;
        if ((r==1&&l==1)||(k==1&&(l==1||r==1))) {
            cout << "YES";
            re;
        }
    }
    cout << "NO";
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok1 = false, ok2 = false, ok = true;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok1 = true;
            save[cnt] = true;
            if (i && save[cnt - 1]) {cout << "NO"; break;}
        }
        else if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok2 = true;
            save[cnt] = true;
            if (i && save[cnt - 1]) {cout << "NO"; break;}
        }
    }
    if (!ok1 || !ok2) cout << "NO";
    else cout << "YES";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok1 = false, ok2 = false, ok = false;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok1 = true;
            save[i] = true;
            if (i && save[i - 1]) {ok = true; cout << "NO"; break;}
        }
        else if (s[i] == 'B' && s[i + 1] == 'A')
        {
            ok2 = true;
            save[i] = true;
            if (i && save[i - 1]) {ok = true; cout << "NO"; break;}
        }
    }
    if (!ok)
    {
        if (!ok1 || !ok2) cout << "NO";
        else cout << "YES";
    }
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok1 = false, ok2 = false, ok = true;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok1 = true;
            save[cnt] = true;
            if (i && save[cnt - 1]) {cout << "NO"; break;}
        }
        else if (s[i] == 'B' && s[i + 1] == 'A')
        {
            ok2 = true;
            save[cnt] = true;
            if (i && save[cnt - 1]) {cout << "NO"; break;}
        }
    }
    if (!ok1 || !ok2) cout << "NO";
    else cout << "YES";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok1 = false, ok2 = false, ok = true;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok1 = true;
            save[cnt] = true;
            if (i && save[cnt - 1]) {ok = false; break;}
        }
        else if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok2 = true;
            save[cnt] = true;
            if (i && save[cnt - 1]) {ok = false; break;}
        }
    }
    if (!ok1 || !ok2 || !ok) cout << "NO";
    else cout << "YES";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok = false;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if ((s[i] == 'A' && s[i + 1] == 'B') || (s[i] == 'B' && s[i + 1] == 'A'))
        {
            dem++;
            save[i] = true;
            ok = true;
            if (i && save[i - 1]) ok = false;
        }
    }
    if (ok || dem >= 3) cout << "YES";
    else cout << "NO";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    bool ok = false;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if ((s[i] == 'A' && s[i + 1] == 'B') || (s[i] == 'B' && s[i + 1] == 'AAA'))
        {
            save[i] = true;
            ok = true;
            if (i && save[i - 1] == true)
            {
                ok = false;
                break;
            }
        }
    }
    if (ok) cout << "YES";
    else cout << "NO";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok1 = false, ok2 = false, ok = true;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            dem++;
            ok1 = true;
            save[i] = true;
            if (i && save[i - 1]) ok = false;
        }
        else if (s[i] == 'B' && s[i + 1] == 'A')
        {
            dem++;
            ok2 = true;
            save[i] = true;
            if (i && save[i - 1]) ok = false;
        }
    }
    if (ok1 && ok2)
    {
        if (ok) cout << "YES";
        else
        {
            if (dem >= 3) cout << "YES";
            else cout << "NO";
        }
    }
    else cout << "NO";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    int firstAB = -1, lastAB, firstBA = -1, lastBA;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            lastAB = i;
            if (firstAB == -1) firstAB = i;
        }
        else if (s[i] == 'B' && s[i + 1] == 'A')
        {
            lastBA = i;
            if (firstBA == -1) firstBA = i;
        }
    }
    if (firstAB == -1 || firstBA == -1) cout << "NO";
    else if (lastBA - firstAB > 1 || lastAB - firstBA > 1) cout << "YES";
    else cout << "NO";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    bool ok = false;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if ((s[i] == 'A' && s[i + 1] == 'B') || (s[i] == 'B' && s[i + 1] == 'A'))
        {
            save[i] = true;
            ok = true;
            if (i && save[i - 1])
            {
                ok = false;
                break;
            }
        }
    }
    if (ok) cout << "YES";
    else cout << "NO";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok1 = false, ok2 = false, ok = true;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok1 = true;
            save[i] = true;
            if (i && save[i - 1]) {cout << "NO"; break;}
        }
        else if (s[i] == 'B' && s[i + 1] == '')
        {
            ok2 = true;
            save[i] = true;
            if (i && save[i - 1]) {cout << "NO"; break;}
        }
    }
    if (!ok1 || !ok2) cout << "NO";
    else cout << "YES";
	return 0;
}


/**
    __author__ : FireGhost
    problems_ID: 550A.cpp
*/

#include <bits/stdc++.h>

using namespace std;

#define mp 					make_pair
#define pb 					push_back
#define fi 					first
#define se 					second
#define all(x)				x.begin(), x.end()
#define endl				"\n"

typedef long long       	ll;
typedef unsigned long long 	ull;
typedef vector<int> 		vi;
typedef pair<int, int>		pii;

const int N = 1e6 + 5;
const int INF = INT_MAX;
const int NEINF = INT_MIN;
// const int MOD = 1e9 + 7;
// ll Add(ll x, ll y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;}
// ll Mul(ll x, ll y) {return (x * y) % MOD;}
// ll BinPow(ll x, ll y) {ll res = 1; while (y) {if (y & 1) res = Mul(res, x); x = Mul(x, x); y >>= 1;} return res;}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int cnt = s.length();
    vector <bool> save(cnt);
    int dem = 0;
    bool ok1 = false, ok2 = false, ok = true;
    for (int i = 0; i < cnt - 1; ++i)
    {
        if (s[i] == 'A' && s[i + 1] == 'B')
        {
            ok1 = true;
            save[i] = true;
            if (i && save[i - 1]) {cout << "NO"; break;}
        }
        else if (s[i] == 'B' && s[i + 1] == 'A')
        {
            ok2 = true;
            save[i] = true;
            if (i && save[i - 1]) {cout << "NO"; break;}
        }
    }
    if (!ok1 || !ok2) cout << "NO";
    else cout << "YES";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char s[100005],s1[100005];
int main()
{
    while(scanf("%s",s)!=EOF)
    {
        bool flag1=false,flag2=false;
        bool flag3=false,flag4=false;
        int l=strlen(s);
        for(int i=0;i<l;i++)
            s1[i]=s[i];
        for(int i=0;i<l-1;i++)
        {
            if(s[i]=='A'&&s[i+1]=='B')
            {
                flag1=true;
                s[i]='Z';
                s[i+1]='Z';
                break;
            }
        }
        for(int i=0;i<l-1;i++)
        {
            if(s[i]=='B'&&s[i+1]=='A')
            {
                flag2=true;
                s[i]='Z';
                s[i+1]='Z';
                break;
            }
        }
        for(int i=0;i<l-1;i++)
        {
            if(s1[i]=='B'&&s1[i+1]=='A')
            {
                flag3=true;
                s1[i]='Z';
                s1[i+1]='Z';
                break;
            }
        }
        for(int i=0;i<l-1;i++)
        {
            if(s1[i]=='A'&&s1[i+1]=='B')
            {
                flag4=true;
                s1[i]='Z';
                s1[i+1]='Z';
                break;
            }
        }
        if((flag1&&flag2)||(flag3&&flag4)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
char s[100005],s1[100005];
int main()
{
    int j=9;
    while(scanf("%s",s)!=EOF)
    {
        bool flag1=false,flag2=false;
        bool flag3=false,flag4=false;
        int l=strlen(s);
        for(int i=0;i<l;i++)
            s1[i]=s[i];
        for(int i=0;i<l-1;i++)
        {
            if(s[i]=='A'&&s[i+1]=='B')
            {
                flag1=true;
                s[i]='Z';
                s[i+1]='Z';
                break;
            }
        }
        for(int i=0;i<l-1;i++)
        {
            if(s[i]=='B'&&s[i+1]=='A')
            {
                flag2=true;
                s[i]='Z';
                s[i+1]='Z';
                break;
            }
        }
        for(int i=0;i<l-1;i++)
        {
            if(s1[i]=='B'&&s1[i+1]=='A')
            {
                flag3=true;
                s1[i]='Z';
                s1[i+1]='Z';
                break;
            }
        }
        for(int i=0;i<l-1;i++)
        {
            if(s1[i]=='A'&&s1[i+1]=='B')
            {
                flag4=true;
                s1[i]='Z';
                s1[i+1]='Z';
                break;
            }
        }
        if((flag1&&flag2)||(flag3&&flag4)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.size(),f1=0,f2=0,i1,i2;
    for(int i=0;i<l-1;i+=2)
    {
        if(s.substr(i,i+2)=="AB")
        {
            f1=1;
            i1=i;
        }
        if(s.substr(i,i+2)=="BA")
        {
            f2=1;
            i2=i;
        }
    }
    if(f1&&f2)
    {
        if(i1!=i2&&(i2!=i1+1&&i1!=i2+1))
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
        cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.size(),f1=0,f2=0,i1,i2;
    for(int i=0;i<l-1;i++)
    {
        if(s.substr(i,i+2)=="AB")
        {
            f1=1;
            i1=i;
        }
        if(s.substr(i,i+2)=="BA")
        {
            f2=1;
            i2=i;
        }
    }
    if(f1&&f2)
    {
        if(i1!=i2&&(i2!=i1+1&&i1!=i2+1))
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
        cout<<"NO";
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i + 2;

			AB++;

			break;

		}

	}

	if(AB){

		for(i = 0; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i;

			AB++;

			break;

		}

	}

	if(AB){

		for(i = in; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')&&i!=in+1){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i;

			AB++;

		}

	}

	if(AB){

		for(i = in; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')&&i!=in+1){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i;

			AB++;

		}

	}

	if(AB){

		for(i = 0; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')&&i+1!=in){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i;

			AB++;

		}

	}

	if(AB){

		for(i = 0; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')&&i!=in+1){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i;

			AB++;

			break;

		}

	}

	if(AB){

		for(i = 0; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')&&i!=in+1){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i + 2;

			AB++;

			break;

		}

	}

	if(AB){

		for(i = in; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i;

			AB++;

		}

	}

	if(AB){

		for(i = 0; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A')&&i!=in+1&&i!=in-1){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


/*
    Code written by Talant I.D.
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;
typedef tuple <int, int, int> tiii;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod 1000000007ll
#define eps (double)1e-9
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}

bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2)
		if(n % i == 0) return false;
	return true;
}

int main(){
    do_not_disturb
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    string s;
    int i;
    vector <int> in1, in2;
    cin >> s;
    for(i = 0; i < s.size()-1; i++){
		if(s[i] == 'A' && s[i+1] == 'B'){
			in1.pb(i);
		}
	}
	for(i = 0; i < s.size()-1; i++){
		if(s[i] == 'B' && s[i+1] == 'A'){
			in2.pb(i);
		}
	}
	if(!in1.size() || !in2.size()){
		cout << "NO";
	}
	else if(in1.size() > 1 || in2.size() > 1){
		cout << "YES";
	}
	else{
		if(in1[0] <= in2[0] && in2[0] <= in1[0]+1 || in2[0] <= in1[0] && in1[0] <= in2[0]+1){
			cout << "NO";
		}
		else{
			cout << "YES";
		}
	}
    return 0;
} // What is to be written here?


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define precision(n)	std fixed << std setprecision(n)

int main(){

	string s;

	cin >> s;

	ll i, in = 0, AB = 0;

	for(i = 0; i < s.size() - 1; i++){

		if((s[i] == 'A' && s[i+1] == 'B')){

			in = i + 2;

			AB++;

			break;

		}

	}

	if(AB){

		for(i = in; i < s.size() - 1; i++){

			if((s[i] == 'B' && s[i+1] == 'A') && i != in+1){

				cout << "YES";

				return 0;

			}

		}

		cout << "NO";

	}

	else{

		cout << "NO";

	}

	return 0;

}


/*
    Code written by Talant I.D.
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;
typedef tuple <int, int, int> tiii;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod 1000000007ll
#define eps (double)1e-9
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}

bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2)
		if(n % i == 0) return false;
	return true;
}

int main(){
    do_not_disturb
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    string s;
    int i;
    vector <int> in1, in2;
    cin >> s;
    for(i = 0; i < s.size()-1; i++){
		if(s[i] == 'A' && s[i+1] == 'B'){
			in1.pb(i);
		}
	}
	for(i = 0; i < s.size()-1; i++){
		if(s[i] == 'B' && s[i+1] == 'A'){
			in2.pb(i);
		}
	}
	for(auto it1 : in1){
		for(auto it2 : in2){
			int a = it1, b = it2;
			if(a > b) swap(a, b);
			if(!(a <= b && b <= a+1)){
				cout << "YES";
				return 0;
			}
		}
	}
	cout << "NO";
    return 0;
} // What is to be written here?


#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define prec(n) fixed<<setprecision(n)
#define vi vector<int>
#define endl "\n"
#define pll pair<ll, ll>
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}
string s;
int n;

void solve()
{
  cin>>s;
  n = s.size() ;

  vector<int> a  , b ;
  for(int i=0 ; i< n-1 ; i++)
  {
    if(s[i]=='A' && s[i+1]=='B')
    a.push_back(i) ;
    if(s[i]=='B' && s[i+1]=='A')
    b.push_back(i) ;
  }
  int ok = 0 ;

  for(int i =0 ; i<a.size() ; i++)
  {
    for(int j = 0 ; j<b.size() ; j++)
    {
      ok = ok|(abs(a[i]-b[j])!=1) ;
    }
  }

  if(ok) cout<<"YES" ;
  else cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fio;
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}
}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	int mina = inf , minb = inf ;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B')  mina=min(mina , i) ;

		if(a[i]=='B' && a[i+1]=='A')  minb=min(minb , i) ;
	}

      if(mina<n)
      {
      	for(int i = mina +2 ; i< n-1 ; i++)
      	{
      		if(a[i]=='B' && a[i+1]=='A') {
      			cout<<"YES";
      			return ;
      		}
      	}
      }

      if(minb<n)
      {
      	for(int i = minb +2 ; i<n-1 ; i++)
      	{
      		if(a[i]=='B' && a[i+1]=='A') {
      			cout<<"YES";
      			return ;
      		}
      	}
      }

      cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	vector<int>  v1 , v2 ;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B')  v1.pb(i) ;

		if(a[i]=='B' && a[i+1]=='A')  v2.pb(i) ;

	}

	for(int i = 0 ; i<v1.size() ; i++)
	{
		for(int j = 0 ; j<v2.size() ; j++)
		{
			if(abs(v1[i]-v2[j])!=1) {
				cout<<"YES"<<endl;
				return ;
			}
		}
	}

	cout<<"NO"<<endl;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	int ok1=inf ,ok2=-1 ,ok3=1;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B') ok1=min(ok1 , i) ;

		if(a[i]=='B' && a[i+1]=='A') ok2=max(ok2, i) ;

		if(ok1<n && ok2 >0 && abs(ok1-ok2)!=1)
		{
			cout<<"YES";
			return  ;
		}

	}

	cout<<"NO"<<endl;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define prec(n) fixed<<setprecision(n)
#define vi vector<int>
#define endl "\n"
#define pll pair<ll, ll>
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}
string s;
int n;

void solve()
{
  cin>>s;
  n = s.size() ;
int x = 0 , y = 0 , z = 0  ;
for(int i=0 ; i<n-2; i++)
{
  if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='A') z++ ;
  if(s[i]=='B' && s[i+1]=='A' && s[i+2]=='B') z++ ;
}
for(int i= 0 ; i<n-1 ; i++)
{
  if(s[i]=='A' && s[i+1]=='B') x++ ;
  if(s[i]=='B' && s[i+1]=='A') y++ ;
}

x-=z , y-=z ;
if((x>0 && z>0) || (y>0 && z>0 ) || (z>=3) || (x>0 && y>0)) cout<<"YES" ;
else cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fio;
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}
}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	int ok1=inf ,ok2=-1 ,ok3=1;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B') ok1=min(ok1 , i) ;

		if(a[i]=='B' && a[i+1]=='A') ok2=max(ok2, i) ;

		if(ok1<n && ok2 >=0 && abs(ok1-ok2)!=1)
		{
			cout<<"YES";
			return  ;
		}

	}

	cout<<"NO"<<endl;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define prec(n) fixed<<setprecision(n)
#define vi vector<int>
#define endl "\n"
#define pll pair<ll, ll>
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}
string s ;
int n ;

void solve()
{
  cin>>s ;
  n = s.size() ;

  int mina=inf , minb=inf ;

  for(int i=0 ; i< n ; i++)
  {
    if(s[i]=='A' && s[i+1]=='B') mina= min(mina , i) ;
    if(s[i]=='B' && s[i+1]=='A') minb= min(minb , i) ;

  }
  int ok = 0 ;

  for(int i= mina+1 ; i<n-1; i++)
  {
    if(s[i]=='B' && s[i+1]=='A') ok = 1;
  }

  for(int i= minb+1 ; i<n-1; i++)
  {
    if(s[i]=='A' && s[i+1]=='A') ok = 1;
  }

  if(ok) cout<<"YES" ;
  else cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fio;
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}
}


#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define prec(n) fixed<<setprecision(n)
#define vi vector<int>
#define endl "\n"
#define pll pair<ll, ll>
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}
string s ;
int n ;

void solve()
{
  cin>>s ;
  n = s.size() ;

  int mina=inf , minb=inf ;

  for(int i=0 ; i< n ; i++)
  {
    if(s[i]=='A' && s[i+1]=='B') mina= min(mina , i) ;
    if(s[i]=='B' && s[i+1]=='A') minb= min(minb , i) ;

  }
  int ok = 0 ;

  for(int i= mina+2 ; i<n-1; i++)
  {
    if(s[i]=='B' && s[i+1]=='A') ok = 1;
  }

  for(int i= minb+2 ; i<n-1; i++)
  {
    if(s[i]=='A' && s[i+1]=='A') ok = 1;
  }

  if(ok==1) cout<<"YES" ;
  else cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fio;
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}
}


#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define prec(n) fixed<<setprecision(n)
#define vi vector<int>
#define endl "\n"
#define pll pair<ll, ll>
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}
string s ;
int n ;

void solve()
{
  cin>>s ;
  n = s.size() ;

  int mina=inf , minb=inf ;

  for(int i=0 ; i< n-1 ; i++)
  {
    if(s[i]=='A' && s[i+1]=='B') mina= min(mina , i) ;
    if(s[i]=='B' && s[i+1]=='A') minb= min(minb , i) ;

  }
  int ok = 0 ;

   if(mina==inf || minb==inf)
   {
     cout<<"NO" ;
     return ;
   }

  for(int i= mina+2 ; i<n-1; i++)
  {
    if(s[i]=='B' && s[i+1]=='A' && i<n && i+1<n) ok = 1;
  }

  for(int i= minb+2 ; i<n-1; i++)
  {
    if(s[i]=='A' && s[i+1]=='B' && i<n && i+1<n) ok = 1;
  }

  if(ok) cout<<"YES" ;
  else cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fio;
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}
}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	int ok1=inf ,ok2=-1 ,ok11=-1 ,ok22 = inf ;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B') ok1=min(ok1 , i) , ok11= max(ok11, i) ;

		if(a[i]=='B' && a[i+1]=='A') ok2=max(ok2, i) , ok22= min(ok2 , i) ;

		if(ok1<n && ok2 >=0 && (abs(ok1-ok2)!=1 || abs(ok11-ok22)!=1) )
		{
			cout<<"YES";
			return  ;
		}

	}

	cout<<"NO"<<endl;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	int mina = inf , minb = inf ;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B')  mina=min(mina , i) ;

		if(a[i]=='B' && a[i+1]=='A')  minb=min(minb , i) ;
	}

      if(mina<n)
      {
      	for(int i = mina +1 ; i< n-1 ; i++)
      	{
      		if(a[i]=='B' && a[i+1]=='A') {
      			cout<<"YES";
      			return ;
      		}
      	}
      }

      if(minb<n)
      {
      	for(int i = minb +1 ; i<n-1 ; i++)
      	{
      		if(a[i]=='B' && a[i+1]=='A') {
      			cout<<"YES";
      			return ;
      		}
      	}
      }

      cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	int ok1=0 ,ok2=0 ,ok3=1;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B') ok1=1 ;

		if(a[i]=='B' && a[i+1]=='A') ok2=1 ;

	}

	for(int i = 0 ; i<n-2 ; i++)
	{
		if(a[i]=='A' && a[i+1]=='B' && a[i+2]=='A') ok3=0;
		if(a[i]=='B' && a[i+1]=='A' && a[i+2]=='B') ok3=0;
	}

	if(ok1 && ok2 && ok3) cout<<"YES" ;
	else cout<<"NO"<<endl;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}


   //                                                   Practice is th key !
//                                                      @shivamisation

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (ll) 998244353
#define MOD (ll) 1e9+7
#define all(a) a.begin(),a.end()
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define loop(i,a,b) for (ll i = a; i <= b; i++)
#define bloop(i,a,b) for (ll i = a ; i>=b;i--)
#define tc ll t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define ff first
#define ss second
#define oj    freopen("input.txt", "r",stdin);  freopen("output.txt", "w",stdout)
#define endl "\n"
#define pll pair<ll, ll>
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         100001
#define inf          INT_MAX
#define zer          INT_MIN
#define vp vector<pll>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define nl cout<<endl
const ll MAXN = (ll)((1e5) + 100);
void pr(ll x) {cout << x;}
void prl(ll x) {cout << x << endl;}

void solve()
{
	string a ; cin>>a ;
	int n = a.size() ;

	int mina = inf , minb = inf ;

	for(int i = 0 ; i <n-1 ;i++)
	{
		if(a[i]=='A' && a[i+1]=='B')  mina=min(mina , i) ;

		if(a[i]=='B' && a[i+1]=='A')  minb=min(minb , i) ;
	}

      if(mina<n)
      {
      	for(int i = mina +2 ; i< n-1 ; i++)
      	{
      		if(a[i]=='B' && a[i+1]=='A') {
      			cout<<"YES";
      			return ;
      		}
      	}
      }

      if(minb<n)
      {
      	for(int i = minb +2 ; i<n-1 ; i++)
      	{
      		if(a[i]=='A' && a[i+1]=='B') {
      			cout<<"YES";
      			return ;
      		}
      	}
      }

      cout<<"NO" ;

}

int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fio;
    //srand(time(NULL));
    int T = 1;
    //cin >> T;

    while (T--){
    solve();
}

}