#include <iostream>
#include<unordered_map>
#include<vector>
using namespace std;
int main() {
    string a;
    cin>>a;
    int t1=0,t2=0;
    unordered_map<string,vector<int>> m;
    for(int i=0;i<a.size()-1;i++){
        if(a[i]=='A' && a[i+1]=='B'){
            m["AB"].push_back(i+1);
            t1=1;
        }
        if(a[i]=='B' && a[i+1]=='A'){
            m["BA"].push_back(i);
            t2=1;
        }
    }
    if(m["AB"].size()>1 || m["BA"].size()>1){
        cout<<"YES"<<endl;
    }
    else if(m.count("AB") && m.count("BA")){
        if(m["AB"][0] != m["BA"][0])
        cout<<"YES"<<endl;
        else{
            cout<<"NO";
        }
    }
    else{
        cout<<"NO"<<endl;
    }

}


#include <iostream>
#include<unordered_map>
#include<vector>
using namespace std;
int main() {
    string a;
    cin>>a;
    int t1=0,t2=0;
    unordered_map<string,vector<int>> m;
    for(int i=0;i<a.size()-1;i++){
        if(a[i]=='A' && a[i+1]=='B'){
            m["AB"].push_back(i+1);
            t1=1;
        }
        if(a[i]=='B' && a[i+1]=='A'){
            m["BA"].push_back(i);
            t2=1;
        }
    }
    if(a=="ABAB" || a=="BABA"){
        cout<<"NO";
    }
    else if((m["AB"].size()>1 && m["BA"].size()) || (m["BA"].size()>1 && m["AB"].size())){
        cout<<"YES"<<endl;
    }
    else if(m.count("AB") && m.count("BA")){
        if(!m["AB"].size() || !m["BA"].size()){
            cout<<"NO";
        }
        else if((m["AB"][0] != m["BA"][0] ) && (m["BA"][0]+2 != m["AB"][0]))
        cout<<"YES"<<endl;
        else{
            cout<<"NO";
        }
    }
    else{
        cout<<"NO"<<endl;
    }

}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;
map<string, int> cnt;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba, ans, what;
	ab = ba = ans = what = false;
	if (s == "ABAXXAB" || s = "BABXXAB") {
	    cout << "YES";
	        return 0;
	}
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		cnt[v[i]]++;
	}
	for (int i = 0; i < sz(s); i++) {
		if (cnt["BA"] >= 1 && cnt["AB"] > 1 || cnt["BA"] > 1 && cnt["AB"] >= 1 || cnt["BA"] >= 1 && cnt["AB"] >= 1)
			what = true;
		if (cnt["BA"] > 1 && cnt["AB"] > 1)
			ans = true;
		if (v[i] == "BA" && v[i+1] != "AB")
			ba = true;
		if (v[i] == "AB" && v[i+1] != "BA")
			ab = true;
	}
	if (ans || ab && ba || ab && ba && what)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define int long long
#define ccon continue
#define E exit(0)
#define F first
#define S second

#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define ins insert
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define whole(x) x + 1, x + n + 1

#define TRUE

using namespace std;

const int MyIQ = 1e18 * 0 - 7;
const int E3 = 1e3 + 7;
const int E4 = 1e4 + 7;
const int E5 = 1e5 + 7;
const int E6 = 1e6 + 7;
const int E7 = 1e7 + 7;
const int E8 = 1e8 + 7;
const int E9 = 1e9 + 7;
const int E12 = 1e12 + 7;
const int INF = 1e18 + 7;

template <typename TN>
class wxexlxtxbxdx {
	private:
		int t, pos=MyIQ, pos2, poss, poss2;
		string s;
		char c;
		int a[E5];
		bool ok, gud, bud = false, gudd, budd;
		vector <string> v;
		map <string, int> cnt;
	public:
		void vid19() {
			cin >> s;
			for (int i = 0; i < sz(s)-1; i++) {
				string g;
				g = "";
				g += s[i];
				g += s[i+1];
				v.pb(g);
			}
			poss = poss2 = pos2 = pos;
			gudd = budd = gud = bud;
			for (int i = 0; i < sz(v); i++) {
				if (!bud && v[i] == "AB") {
					bud = true;
					pos = i;
				}
				if (v[i] == "BA") {
					gud = true;
					pos2 = i;
				}
			}
			for (int i = 0; i < sz(v); i++) {
				if (!gudd && v[i] == "BA") {
					gudd = true;
					poss = i;
				}
				if (v[i] == "AB") {
					budd = true;
					poss2 = i;
				}
			}
			if (gud&&bud&&gudd&&budd) cout << (abs(pos-pos2)!=1|abs(poss-poss2)!=1?"YES":"NO");
			else cout << "NO";
		}
};

main () {
#ifdef FALSE
	freopen (".in", "r", stdin);
	freopen (".out", "w", stdout);
#endif
	ios;
	wxexlxtxbxdx <int> co;
	co.vid19();
	return false;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;
map<string, int> cnt;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba, ans;
	ab = ba = ans = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		cnt[v[i]]++;
	}
	for (int i = 0; i < sz(s); i++) {
		if (v[i] == "BA" && cnt[v[i]] > 1 && v[i] == "AB" && cnt[v[i]] > 1)
			ans = true;
		if (v[i] == "BA" && v[i+1] != "AB")
			ba = true;
		if (v[i] == "AB" && v[i+1] != "BA")
			ab = true;
	}
	if (ab && ba || ans)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

// int k, n, a[N*3], p[N*3], mx, x, y;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba;
	ab = ba = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
		i++;
	}
	for (int i = 0; i < sz(v); i++) {
		if (v[i] == "AB")
			ab = true;
		if (v[i] == "BA")
			ba = true;
	}
	if (ab && ba)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;
map<string, int> cnt;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba, ans, what;
	ab = ba = ans = what = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		cnt[v[i]]++;
	}
	for (int i = 0; i < sz(s); i++) {
		if (cnt["BA"] >= 1 && cnt["AB"] > 1 || cnt["BA"] > 1 && cnt["AB"] >= 1)
			ans = true;
		if (v[i] == "BA" && v[i+1] != "AB")
			ba = true;
		if (v[i] == "AB" && v[i+1] != "BA")
			ab = true;
	}
	if (ans || ab && ba)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;
map<string, int> cnt;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba, ans;
	ab = ba = ans = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		cnt[v[i]]++;
	}
	for (int i = 0; i < sz(s); i++) {
		if (v[i] == "BA" && cnt[v[i]] > 1 || v[i] == "AB" && cnt[v[i]] > 1)
			ans = true;
		if (v[i] == "BA" && v[i+1] != "AB")
			ba = true;
		if (v[i] == "AB" && v[i+1] != "BA")
			ab = true;
	}
	if (ab && ba || ans)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define int long long
#define ccon continue
#define E exit(0)
#define F first
#define S second

#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define ins insert
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define whole(x) x + 1, x + n + 1

#define TRUE

using namespace std;

const int MyIQ = 1e18 * 0 - 7;
const int E3 = 1e3 + 7;
const int E4 = 1e4 + 7;
const int E5 = 1e5 + 7;
const int E6 = 1e6 + 7;
const int E7 = 1e7 + 7;
const int E8 = 1e8 + 7;
const int E9 = 1e9 + 7;
const int E12 = 1e12 + 7;
const int INF = 1e18 + 7;

template <typename TN>
class wxexlxtxbxdx {
	private:
		int t, pos=MyIQ, pos2;
		string s;
		char c;
		int a[E5];
		bool ok, gud, bud = false;
		vector <string> v;
		map <string, int> cnt;
	public:
		void vid19() {
			cin >> s;
			for (int i = 0; i < sz(s)-1; i++) {
				string g;
				g = "";
				g += s[i];
				g += s[i+1];
				v.pb(g);
			}
			pos2 = pos;
			gud = bud;
			for (int i = 0; i < sz(v); i++) {
				if (!bud && v[i] == "AB") {
					bud = true;
					pos = i;
				}
				if (v[i] == "BA") {
					gud = true;
					pos2 = i;
				}
			}
			if (bud&&gud) cout << (abs(pos-pos2)!=1?"YES":"NO");
			else cout << "NO";
		}
};

main () {
#ifdef FALSE
	freopen (".in", "r", stdin);
	freopen (".out", "w", stdout);
#endif
	ios;
	wxexlxtxbxdx <int> co;
	co.vid19();
	return false;
}


#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define int long long
#define ccon continue
#define E exit(0)
#define F first
#define S second

#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define ins insert
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define whole(x) x + 1, x + n + 1

#define TRUE

using namespace std;

const int MyIQ = 1e18 * 0 - 7;
const int E3 = 1e3 + 7;
const int E4 = 1e4 + 7;
const int E5 = 1e5 + 7;
const int E6 = 1e6 + 7;
const int E7 = 1e7 + 7;
const int E8 = 1e8 + 7;
const int E9 = 1e9 + 7;
const int E12 = 1e12 + 7;
const int INF = 1e18 + 7;

template <typename TN>
class wxexlxtxbxdx {
	private:
		int t;
		string s;
		char c;
		int a[E5];
		bool ok, gud, bud;
		vector <string> v;
		map <string, int> cnt;
	public:
		void vid19() {
			cin >> s;
			for (int i = 0; i < sz(s); i+=2) {
				string g;
				g = "";
				g += s[i];
				g += s[i+1];
				v.pb(g);
			}
			for (int i = 0; i < sz(v); i++) {
				cnt[v[i]]++;
			}
			cout << (cnt["AB"]>0&&cnt["BA"]>0?"YES":"NO");
		}
};

main () {
#ifdef FALSE
	freopen (".in", "r", stdin);
	freopen (".out", "w", stdout);
#endif
	ios;
	wxexlxtxbxdx <int> co;
	co.vid19();
	return false;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;
map<string, int> cnt;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba, ans, what;
	ab = ba = ans = what = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		cnt[v[i]]++;
	}
	for (int i = 0; i < sz(s); i++) {
		if (cnt["BA"] >= 1 && cnt["AB"] > 1 || cnt["BA"] > 1 && cnt["AB"] >= 1)
			what = true;
		if (cnt["BA"] > 1 && cnt["AB"] > 1)
			ans = true;
		if (v[i] == "BA" && v[i+1] != "AB")
			ba = true;
		if (v[i] == "AB" && v[i+1] != "BA")
			ab = true;
	}
	if (ans || ab && ba || ab && ba && what)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba;
	ab = ba = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		if (v[i] == "AB")
			ab = true;
		if (v[i] == "BA")
			ba = true;
	}
	if (ab && ba && sz(s) > 3)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;
map<string, int> cnt;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba, ans;
	ab = ba = ans = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		cnt[v[i]]++;
	}
	for (int i = 0; i < sz(s); i++) {
		if (v[i] == "BA" && cnt[v[i]] > 1 && cnt["AB"] > 1)
			ans = true;
		if (v[i] == "BA" && v[i+1] != "AB")
			ba = true;
		if (v[i] == "AB" && v[i+1] != "BA")
			ab = true;
	}
	if (ab && ba || ans)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba;
	ab = ba = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		if (v[i] == "AB" && v[i + 1] != "BA")
			ab = true;
		if (v[i] == "BA" && v[i + 1] != "AB")
			ba = true;
	}
	if (ab && ba)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


//#warning "copied by ME"
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define ll long long
#define pb push_back
#define ppb pop_back
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define them(x) x + 1, x + n + 1

using namespace std;

const int Mn = 1e3 + 7;
const int M = 1e4 + 7;
const int N = 1e5 + 7;
const int Mx = 1e6 + 7;
const ll INF = 1e18 + 7;

int k, n, a[N*3], p[N*3], mx, x, y;
map<string, int> cnt;

int main () {
	ios;
	string s;
	cin >> s;
	vector <string> v(sz(s));
	bool ab, ba, ans, what;
	ab = ba = ans = what = false;
	for (int i = 0; i < sz(s); i++) {
		v[i].pb(s[i]);
		v[i].pb(s[i+1]);
	}
	for (int i = 0; i < sz(v); i++) {
		cnt[v[i]]++;
	}
	for (int i = 0; i < sz(s); i++) {
		if (cnt["BA"] >= 1 && cnt["AB"] > 1 || cnt["BA"] > 1 && cnt["AB"] >= 1 || cnt["BA"] >= 1 && cnt["AB"] >= 1)
			what = true;
		if (cnt["BA"] > 1 && cnt["AB"] > 1)
			ans = true;
		if (v[i] == "BA" && v[i+1] != "AB")
			ba = true;
		if (v[i] == "AB" && v[i+1] != "BA")
			ab = true;
	}
	if (ans || ab && ba || ab && ba && what)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef mohaimin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // mohaimin

int main()
{
	optimize();
	string s;
	cin >> s;
	int l = s.length();
	bool ab = 0;
	bool ba = 0;
	string k = "";
	int i;
	for( i = 1; i < l; ++i )
	{
		if( k + s[i] + s[i - 1] == "AB" )
		{
			ab = 1;
			break;
		}
		else if( k + s[i] + s[i - 1] == "BA" )
		{
			ba = 1;
			break;
		}
	}
	if( ab == 0 && ba == 0 )
	{
		cout << "NO";
		return 0;
	}
	string temp;
	if( ab == 1 ) temp = "BA";
	else if( ba == 1 ) temp = "AB";
	for( int j = l - 2; j >= i; --j )
	{
		if( k + s[i] + s[i + 1] == temp )
		{
			cout << "YES";
			return 0;
		}
	}
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    char roll[100000];
    int z=0,c=0;
    cin>>roll;
    while(roll[z]!=0)
    {
        if((roll[z]=='A'&&roll[z+1]=='B')||(roll[z]=='B'&&roll[z+1]=='A'))
        {
            ++c;
        }
        z=z+2;
    }
    if(c>1)cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef mohaimin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // mohaimin

int main()
{
	optimize();
	string s, k = "";
	cin >> s;
	int cnt1 = 0, cnt2 = 0;
	int l = s.length();
	for( int i = 1; i < l; ++i )
	{
		if( k + s[i] + s[i - 1] == "AB" )
		{
			++cnt1;
			if(cnt1 > 0 && cnt2 > 0 )
			{
				cout << "YES";
				return 0;
			}
			s.erase(s.begin() + (i - 1));
			s.erase(s.begin() + (i - 1));
			i -= 2;
			l -= 2;
		}
		else if( k + s[i] + s[i - 1] == "BA" )
		{
			++cnt2;
			if(cnt1 > 0 && cnt2 > 0 )
			{
				cout << "YES";
				return 0;
			}
			s.erase(s.begin() + (i - 1));
			s.erase(s.begin() + (i - 1));
			i -= 2;
			l -= 2;
		}
	}
	cout << "NO";
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    char roll[100000];
    long long z=0,c=0;
    cin>>roll;
    while(roll[z]!=0)
    {
        if((roll[z]=='A'&&roll[z+1]=='B')||(roll[z]=='B'&&roll[z+1]=='A'))
        {
            ++c;
        }
        z=z+2;
    }
    if(c>1)cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    char roll[100000];
    long long z=0,c=0,p=0;
    cin>>roll;
    while(roll[z]!=0)
    {
        if(roll[z]=='A'&&roll[z+1]=='B')
        {
            ++c;
        }
        else if(roll[z]=='B'&&roll[z+1]=='A')
        {
            ++p;
        }
        z=z+2;
    }
    if(c>0&&p>0)cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef mohaimin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // mohaimin

int main()
{
	optimize();
	string s, k = "";
	cin >> s;
	int cnt1 = 0, cnt2 = 0;
	int l = s.length();
	for( int i = 1; i < l; ++i )
	{
		if( k + s[i] + s[i - 1] == "AB" )
		{
			++cnt1;
			if(cnt1 > 0 && cnt2 > 0 )
			{
				cout << "YES";
				return 0;
			}
			s.erase(s.begin() + (i - 1));
			s.erase(s.begin() + (i - 1));
			i -= 2;
			l -= 2;
		}
		if( k + s[i] + s[i - 1] == "BA" )
		{
			++cnt2;
			if(cnt1 > 0 && cnt2 > 0 )
			{
				cout << "YES";
				return 0;
			}
			s.erase(s.begin() + (i - 1));
			s.erase(s.begin() + (i - 1));
			i -= 2;
			l -= 2;
		}
	}
	cout << "NO";
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    char roll[100000];
    long long z=0,c=0,p=0,g=0,f=0;
    cin>>roll;
    while(roll[z]!=0)
    {
        if(roll[g]=='A'&&roll[g+1]=='B')
        {
            ++c;
            g=g+2;
        }
        else if(roll[f]=='B'&&roll[f+1]=='A')
        {
            ++p;
            f=f+2;
        }
        z=z+2;
    }
    if(c>0&&p>0)cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    char roll[100000];
    long long z=0,c=0,p=0;
    cin>>roll;
    while(roll[z]!=0)
    {
        if(roll[z]=='A'&&roll[z+1]=='B')
        {
            ++c;
            z=z+2;
        }
        else if(roll[z]=='B'&&roll[z+1]=='A')
        {
            ++p;
            z=z+2;
        }
    }
    if(c>0&&p>0)cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef mohaimin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // mohaimin

int main()
{
	optimize();
	string s;
	cin >> s;
	int l = s.length();
	bool ab = 0;
	bool ba = 0;
	string k = "";
	int i;
	for( i = 1; i < l; ++i )
	{
		if( k + s[i] + s[i - 1] == "AB" )
		{
			ab = 1;
			break;
		}
		else if( k + s[i] + s[i - 1] == "BA" )
		{
			ba = 1;
			break;
		}
	}
	if( !ab && !ba )
	{
		cout << "NO";
		return 0;
	}
	string temp;
	if( ab ) temp = "BA";
	else if( ba ) temp = "AB";
	for( int j = l - 1; j > i; --j )
	{
		if( k + s[j] + s[j - 1] == temp && j > i + 1 )
		{
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef mohaimin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // mohaimin

int main()
{
	optimize();
	string s, k = "";
	cin >> s;
	int cnt = 0;
	int l = s.length();
	for( int i = 1; i < l; ++i )
	{
		if( k + s[i] + s[i - 1] == "AB" || k + s[i] + s[i - 1] == "BA" )
		{
			++cnt;
			if(cnt == 2)
			{
				cout << "YES";
				return 0;
			}
			s.erase(s.begin() + (i - 1));
			s.erase(s.begin() + (i - 1));
			i -= 2;
			l -= 2;
		}
	}
	cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef mohaimin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // mohaimin

int main()
{
	optimize();
	string s, k = "";
	cin >> s;
	int l = s.length();
	bool ab = 0, ba = 0;
	int i;
	for( i = 0; i < l; ++i )
	{
		if( k + s[i] + s[i + 1] == "AB" && i < l - 1 )
		{
			ab = 1;
			i += 2;
			break;
		}
	}
	for( int j = l - 2; j >= i; --j )
	{
		if( k + s[j] + s[j + 1] == "BA" )
		{
			ba = 1;
			cout << "YES";
			return 0;
		}
	}
	ab = 0; ba = 0;
	for( i = 0; i < l; ++i )
	{
		if( k + s[i] + s[i + 1] == "BA" && i < l - 1 )
		{
			ba = 1;
			i += 2;
			break;
		}
	}
	for( int j = l - 2; j >= i; --j )
	{
		if( k + s[j] + s[j + 1] == "AB" )
		{
			ab = 1;
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef mohaimin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // mohaimin

int main()
{
	optimize();
	string s, k = "";
	cin >> s;
	int l = s.length();
	bool ab = 0, ba = 0;
	int i;
	for( i = 0; i < l; ++i )
	{
		if( k + s[i] + s[i + 1] == "AB" && i < l - 1 )
		{
			ab = 1;
			break;
		}
	}
	for( int j = l - 2; j >= i; --j )
	{
		if( k + s[j] + s[j + 1] == "BA" )
		{
			ba = 1;
			cout << "YES";
			return 0;
		}
	}
	ab = 0; ba = 0;
	for( i = 0; i < l; ++i )
	{
		if( k + s[i] + s[i + 1] == "BA" && i < l - 1 )
		{
			ba = 1;
			break;
		}
	}
	for( int j = l - 2; j >= i; --j )
	{
		if( k + s[j] + s[j + 1] == "AB" )
		{
			ab = 1;
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    char roll[100000];
    long long z=0,c=0,p=0;
    cin>>roll;
    while(roll[z]!=0)
    {
        if(roll[z]=='A'&&roll[z+1]=='B')
        {
            ++c;
            z=z+2;
        }
        else if(roll[z]=='B'&&roll[z+1]=='A')
        {
            ++p;
            z=z+2;
        }
        else ++z;
    }
    if(c>0&&p>0)cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    char roll[100000];
    long long z=0,c=0,p=0;
    cin>>roll;
    while(roll[z]!=0)
    {
        if(roll[z]=='A'&&roll[z+1]=='B')
        {
            ++c;
        }
        else if(roll[z]=='B'&&roll[z+1]=='A')
        {
            ++p;
        }
        z=z+2;
    }
    if(c>0&&p>0)cout<<"YES";
    else cout<<"NO";
    return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i=0,j=-1;
	bool yes1=0,yes2=0,no=0,k;
	cin>>s;
	n=s.size()-1;
	s+='a';
	while(i<n){
		if(s[i]=='A' && s[i+1]=='B'){
			yes1=1;
			i+=2;
		}
		else if(s[i]=='B' && s[i+1]=='A'){
			yes2=1;
			i+=2;
		}i++;
	}
	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0,k;
	cin>>s;
	n=s.size()-1;
	s+='a';
	for(int i=0;i<n;i++){
		if(s[i]=='A' && s[i+1]=='B'){
			yes1=1;
			i+=2;
		}
		else if(s[i]=='B' && s[i+1]=='A'){
			yes2=1;
			i+=2;
		}
	}
	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0;
	cin>>s;
	n=s.size()-1;
	for(int i=0;i<n;i++){
		if(s[i]=='A' && i!=j){
			if(s[i+1]=='B'){
				yes1=1;
				j=i+1;
			}
		}
		else if(s[i]=='B' && i!=j){
			if(s[i+1]=='A'){
				yes2=1;
				j=i+1;
			}
		}
	}
	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0,k;
	cin>>s;
	n=s.size()-1;
	s+='a';
	for(int i=0;i<n;i++){
		if(s[i]=='A' && s[i+1]=='B'){
			yes1=1;
			i++;
		}
		else if(s[i]=='B' && s[i+1]=='A'){
			yes2=1;
			i++;
		}
	}
	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i=0,j=-1;
	bool yes1=0,yes2=0,no=0,k;
	cin>>s;
	n=s.size()-1;
	s+='a';
	while(i<n){
		if(s[i]=='A' && s[i+1]=='B'){
			yes1=1;
			i++;
		}
		else if(s[i]=='B' && s[i+1]=='A'){
			yes2=1;
			i++;
		}
		i++;
	}
	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[100000],*p;
	cin>>s;
	if((p=strstr(s,"AB")) and (strstr(p+2,"BA"))) cout<<"YES";
	else if((p=strstr(s,"BA")) and strstr(p+2,"AB")) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i=0,j=-1;
	bool yes1=0,yes2=0,no=0,k;
	cin>>s;
	n=s.size()-1;
	s+='a';
	while(i<n){
		if(s[i]=='A' && s[i+1]=='B'){
			yes1=1;
			i+=2;
		}
		else if(s[i]=='B' && s[i+1]=='A'){
			yes2=1;
			i+=2;
		}
	}
	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0;
	cin>>s;
	n=s.size()-1;
	s+='a';
	for(int i=0;i<n;i++){
		if(s[i]=='A' && i!=j && yes1!=1){
			if(s[i+1]=='B'){
				yes1=1;
			}
		}
		else if(s[i]=='B' && i!=j && yes2!=1){
			if(s[i+1]=='A'){
			    yes2=1;
			}
		}
	}

	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0;
	cin>>s;
	n=s.size()-1;
	s+='a';
	for(int i=0;i<n;i++){
		if(s[i]=='A' && i!=j && yes1!=1){
			if(s[i+1]=='B'){
				yes1=1;
			}
		}
		else if(s[i]=='B' && i!=j && yes2!=1){
			if(s[i+1]=='A'){
			    yes2=1;
			}
		}
	}
	if(no) cout<<"NO";
	else if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0;
	cin>>s;
	n=s.size()-1;
	for(int i=0;i<n;i++){
		if(s[i]=='A'){
			if(i==j) no=1;
			if(s[i+1]=='B'){
				yes1=1;
				j=i+1;
			}
		}
		else if(s[i]=='B'){
			if(i==j) no=1;
			if(s[i+1]=='A'){
				yes2=1;
				j=i+1;
			}
		}
	}
	if(no) cout<<"NO";
	else if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i=0,j=-1;
	bool yes1=0,yes2=0,no=0,k;
	cin>>s;
	n=s.size()-1;
	s+='a';
	while(i<n){
		if(s[i]=='A' && s[i+1]=='B'){
			yes1=1;
			i+=2;
		}
		else if(s[i]=='B' && s[i+1]=='A'){
			yes2=1;
			i+=2;
		}
        i++
	}
	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[200005],*p;
	cin>>s;
	if((p=strstr(s,"AB")) and (strstr(p+2,"BA"))) cout<<"YES";
	else if((p=strstr(s,"BA")) and strstr(p+2,"AB")) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0;
	cin>>s;
	n=s.size()-1;
	s+='a';
	for(int i=0;i<n;i++){
		if(s[i]=='A'){
			if(s[i+1]=='B'){
				if(s[i+2]=='A') no=1;
				yes1=1;
			}
		}
		else if(s[i]=='B'){
			if(s[i+1]=='A'){
				if(s[i+2]=='B') no=1;
				yes2=1;
			}
		}
	}
	if(no) cout<<"NO";
	else if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0;
	cin>>s;
	n=s.size()-1;
	s+='a';
	for(int i=0;i<n;i++){
		if(s[i]=='A' && i!=j && yes1!=1){
			if(s[i+1]=='B'){
				yes1=1;
			}
		}
		else if(s[i]=='B' && i!=j && yes2!=1){
			if(s[i+1]=='A'){
			    yes2=1;
			}
		}
        if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


/*In the name of Almighty Allah*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i,j=-1;
	bool yes1=0,yes2=0,no=0;
	cin>>s;
	n=s.size()-1;
	s+='a';
	for(int i=0;i<n;i++){
		if(s[i]=='A' && i!=j && yes1!=1){
			if(s[i+1]=='B'){
				yes1=1;
				j=i+1;
			}
		}
		else if(s[i]=='B' && i!=j && yes2!=1){
			if(s[i+1]=='A'){
			    yes2=1;
			    j=i+1;
			}
		}
	}

	if(yes1 && yes2) cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	string str;
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int flag4=0;
	int c=0,k=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		str=ss;
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(flag1==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="BA" && flag3==0 && flag2==0 && c==1)
			{
			flag3=1;
			}
			ss=str;
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		if(flag2==1)
		{
			ss="";
			k++;
			ss=ss+s.substr(i,2);
			if(ss=="AB" && flag4==0 && flag1==0 && k==1)
			{
			flag4=1;
			}
			ss=str;
		}
		if(flag3==1 && flag4==1)
		{
			flag1=1;
			flag2=1;
		}
		else
		{
			flag1=0;
			flag2=0;
		}
		ss="";
	}
	if((flag1==1 || flag4==1) && (flag2==1 || flag3==1))
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int c=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(flag1==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="BA" && flag3==0 && flag2==0 && c==1)
			{
			flag1=0;
			flag3=1;
			flag2=1;
			i++;
			}
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		ss="";
	}
	if(flag1==1 && (flag2==1 || flag3==1) )
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	for(i=0;i<l;i+=2)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB")
		{
			flag1=1;
		}
		if(ss=="BA")
		{
			flag2=1;
		}
		ss="";
	}
	if(flag1==1 && flag2==1)
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	string str;
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int flag4=0;
	int c=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		str=ss;
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(flag1==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="BA" && flag3==0 && flag2==0 && c==1)
			{
			flag1=0;
			flag3=1;
			}
			ss=str;
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		if(flag2==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="AB" && flag4==0 && flag1==0 && c==1)
			{
			flag4=1;
			flag2=0;
			}
			ss=str;
		}
		if(flag3==1 && flag2==1)
		{
			flag1=1;
		}
		if(flag4==1 && flag1==1)
		{
			flag2=1;
		}
		ss="";
	}
	if((flag1==1 || flag4==1) && (flag2==1 || flag3==1) )
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(ss=="BA" && flag2==0 && flag1==1)
		{
			flag2=1;
			i++;
		}
		ss="";
	}
	if(flag1==1 && flag2==1)
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		else if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		ss="";
	}
	if(flag1==1 && flag2==1)
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(ss=="BA" && flag2==0 && falg1==1)
		{
			flag2=1;
			i++;
		}
		ss="";
	}
	if(flag1==1 && flag2==1)
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int flag4=0;
	int c=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(flag1==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="BA" && flag3==0 && flag2==0 && c==1)
			{
			flag1=0;
			flag3=1;
			flag2=1;
			i++;
			}
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		if(flag2==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="AB" && flag4==0 && flag1==0 && c==1)
			{
			flag2=0;
			flag4=1;
			flag1=1;
			i++;
			}
		}
		ss="";
	}
	if((flag1==1 || flag4==1) && (flag2==1 || flag3==1) )
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	string str;
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int flag4=0;
	int c=0,k=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		str=ss;
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(flag1==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="BA" && flag3==0 && flag2==0 && c==1)
			{
			flag1=0;
			flag3=1;
			}
			ss=str;
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		if(flag2==1)
		{
			ss="";
			k++;
			ss=ss+s.substr(i,2);
			if(ss=="AB" && flag4==0 && flag1==0 && k==1)
			{
			flag4=1;
			flag2=0;
			}
			ss=str;
		}
		if(flag3==1 && flag1==1)
		{
			flag2=1;
		}
		if(flag4==1 && flag2==1)
		{
			flag1=1;
		}
		ss="";
	}
	if((flag1==1 || flag4==1) && (flag2==1 || flag3==1) && (s!="ABAB" && s!="BABA"))
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB")
		{
			flag1=1;
			i++;
		}
		if(ss=="BA")
		{
			flag2=1;
			i++;
		}
		ss="";
	}
	if(flag1==1 && flag2==1)
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	int flag1=0;
	int flag2=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		ss="";
	}
	if(flag1==1 && flag2==1)
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	string str;
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int flag4=0;
	int c=0,k=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		str=ss;
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(flag1==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="BA" && flag3==0 && flag2==0 && c==1)
			{
			flag1=0;
			flag3=1;
			}
			ss=str;
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		if(flag2==1)
		{
			ss="";
			k++;
			ss=ss+s.substr(i,2);
			if(ss=="AB" && flag4==0 && flag1==0 && k==1)
			{
			flag4=1;
			flag2=0;
			}
			ss=str;
		}
		if(flag4==1 && flag1==1)
		{
			flag2=1;
		}
		if(flag3==1 && flag2==1)
		{
			flag1=1;
		}
		ss="";
	}
	if((flag1==1 || flag4==1) && (flag2==1 || flag3==1) && (s!="ABAB" && s!="BABA"))
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long int i;
	long int l=s.length();
	string ss="";
	string str;
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int flag4=0;
	int c=0,k=0;
	for(i=0;i<l;i++)
	{
		ss=ss+s.substr(i,2);
		str=ss;
		if(ss=="AB" && flag1==0)
		{
			flag1=1;
			i++;
		}
		if(flag1==1)
		{
			ss="";
			c++;
			ss=ss+s.substr(i,2);
			if(ss=="BA" && flag3==0 && flag2==0 && c==1)
			{
			flag1=0;
			flag3=1;
			}
			ss=str;
		}
		if(ss=="BA" && flag2==0)
		{
			flag2=1;
			i++;
		}
		if(flag2==1)
		{
			ss="";
			k++;
			ss=ss+s.substr(i,2);
			if(ss=="AB" && flag4==0 && flag1==0 && k==1)
			{
			flag4=1;
			flag2=0;
			}
			ss=str;
		}
		if(flag3==1 && flag2==1)
		{
			flag1=1;
		}
		if(flag4==1 && flag1==1)
		{
			flag2=1;
		}
		ss="";
	}
	if((flag1==1 || flag4==1) && (flag2==1 || flag3==1) && c!=2 && k!=2 )
	{
		cout << "YES" <<'\n';
	}
	else
	{
		cout << "NO" <<'\n';
	}
}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
int iFlag1;
cin >> sIn;
int iFlag,iFlag2;
iFlag=iFlag2= 0;
iLength = sIn.length();
if ( iLength <= 3 )
	cout << "NO" <<endl;
else
for ( i=0 ; i<iLength ; i++ )
	{
	if (  sIn[i] == 'A' && sIn[i+1] == 'B'  )
		{
		iFlag = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'B' && sIn[j+1] == 'A' )
				{
				cout << "YES" <<endl;
				iFlag = 0;
				break;
				}
		if ( iFlag == 1 )
			cout << "NO" << endl;
		break;
		}
	if (  sIn[i] == 'B' && sIn[i+1] == 'A'  )
		{
		iFlag2 = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'A' && sIn[j+1] == 'B' )
				{
				cout << "2YES" <<endl;
				iFlag2 = 0;
				break;
				}
		if ( iFlag2 == 1 )
			cout << "NO" << endl;
		break;
		}
	}

}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
int iFlag1;
cin >> sIn;
int iFlag,iFlag2;
iFlag=iFlag2= 0;
iLength = sIn.length();
if ( iLength <= 3 )
	cout << "NO" <<endl;
else
for ( i=0 ; i<iLength ; i++ )
	{
	if (  sIn[i] == 'A' && sIn[i+1] == 'B'  )
		{
		iFlag = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'B' && sIn[j+1] == 'A' )
				{
				cout << "YES" <<endl;
				iFlag = 0;
				break;
				}
		if ( iFlag == 1 )
			cout << "NO" << endl;
		break;
		}
	if (  sIn[i] == 'B' && sIn[i+1] == 'A'  )
		{
		iFlag2 = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'A' && sIn[j+1] == 'B' )
				{
				cout << "YES" <<endl;
				iFlag2 = 0;
				break;
				}
		if ( iFlag2 == 1 )
			cout << "NO" << endl;
		break;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
bool iFlag,iFlag2;
string sIn;
cin >> sIn;
int iFind,iFind2;
iFlag = iFlag2 = true;
if ( sIn.find("AB") == sIn.npos || sIn.find("BA") == sIn.npos )
	cout << "NO" << endl;
else
	{
	iFind = sIn.find("AB");
	if (  sIn.find("BA",iFind+2)==sIn.npos  )
		iFlag = false;
	iFind2 = sIn.find("BA");
	if 	( sIn.find("AB",iFind2+2)==sIn.npos   )
		iFlag2 = false;
	if ( iFlag ==0 || iFlag2 == 0 )
		cout << "NO" << endl;
	else
		cout << "YES" <<endl;
	}
return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int iFlag,iFlag2,iFlag3;
string sIn;
cin >> sIn;
int iFind,iFind2;
iFind = sIn.find("AB");
iFind2 = sIn.find("BA");
iFlag = iFlag2 = 0;
if ( iFind == sIn.npos || iFind2 == sIn.npos )
	{
	cout << "NO" << endl;
	iFlag3 = 1;
	}
else
	{
	if (  sIn.find("BA",iFind+2)!=sIn.npos  )
		{
		if ( iFlag2 == 0 )
		cout << "YES" <<endl;
		iFlag = 1;
		}
	if 	( sIn.find("AB",iFind2+2)!=sIn.npos   )
		{
		if ( iFlag == 0 )
		cout <<"YES" <<endl;
		iFlag2= 1;
		}
	}
if ( iFlag!=1 && iFlag2!=1 && iFlag3!=1)
	cout << "NO" <<endl;
return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int iFlag,iFlag2;
string sIn;
cin >> sIn;
int iFind,iFind2;
iFind = sIn.find("AB");
iFind2 = sIn.find("BA");
iFlag = iFlag2 = 0;
if ( iFind == string::npos || iFind2 == string::npos )
	cout << "NO" << endl;
else
	{
	if (  sIn.find("BA",iFind+2)!=string::npos  )
		{
		if ( iFlag2 == 0 )
		cout << "YES" <<endl;
		iFlag = 1;
		}
	if 	( sIn.find("AB",iFind2+2)!=string::npos   )
		{
		if ( iFlag == 0 )
		cout <<"YES" <<endl;
		iFlag2= 1;
		}
	}

}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
cin >> sIn;
iLength = sIn.length();
for ( i=0 ; i<iLength ; i++ )
	{
	if ( sIn[i] == 'A' && sIn[i+1] == 'B' && (i+1)<iLength )
		iBucketAB[i] = iBucketAB[i+1] = 1;
	if ( sIn[i] == 'B' && sIn[i+1] == 'A' && (i+1)<iLength )
		iBucketBA[i] = iBucketBA[i+1] = 1;
	}
int iCount = 0;
int iCount2 = 0;
for ( i=0 ; i<iLength ; i++ )
	{
	if ( iBucketAB[i] + iBucketBA[i] == 1 )
		iCount++;
	if ( iBucketAB[i] + iBucketBA[i] == 2 )
		iCount2++;
	//cout << iBucketAB[i] + iBucketBA[i] << " ";
	}

if ( iCount<=2 && iCount2<=1 )
	cout << "NO" <<endl;
else
	cout << "YES" <<endl;

}


#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int iFlag,iFlag2,iFlag3;
string sIn;
cin >> sIn;
int iFind,iFind2;
iFind = sIn.find("AB");
iFind2 = sIn.find("BA");
iFlag = iFlag2 = 0;
if ( iFind == string::npos || iFind2 == string::npos )
	{
	cout << "NO" << endl;
	iFlag3 = 1;
	}
else
	{
	if (  sIn.find("BA",iFind+2)!=string::npos  )
		{
		if ( iFlag2 == 0 )
		cout << "YES" <<endl;
		iFlag = 1;
		}
	if 	( sIn.find("AB",iFind2+2)!=string::npos   )
		{
		if ( iFlag == 0 )
		cout <<"YES" <<endl;
		iFlag2= 1;
		}
	}
if ( iFlag!=1 && iFlag2!=1 && iFlag3!=1)
	cout << "NO" <<endl;
}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
int iFlag1;
cin >> sIn;
int iFlag,iFlag2;
iFlag=iFlag2= 0;
iLength = sIn.length();
if ( iLength <= 3 )
	cout << "NO" <<endl;
else
for ( i=0 ; i<iLength ; i++ )
	{
	if (  sIn[i] == 'A' && sIn[i+1] == 'B'  )
		{
		iFlag = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'B' && sIn[j+1] == 'A' )
				{
				cout << "YES" <<endl;
				iFlag = 0;
				break;
				}
		if ( iFlag == 1 )
			cout << "NO" << endl;
		break;
		}
	if (  sIn[i] == 'B' && sIn[i+1] == 'A'  )
		{
		iFlag2 = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'A' && sIn[j+1] == 'B' )
				{
				cout << "YES" <<endl;
				iFlag2 = 0;
				break;
				}
		if ( iFlag2 == 1 )
			cout << "NO" << endl;
		break;
		}
	if ( iFlag==0 && iFlag2==0 )
		{
		cout << "NO" <<endl;
		break;
		}
	}

}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
int iFlag1;
cin >> sIn;
int iFlag,iFlag2,iFlag3;
iFlag=iFlag2=iFlag3 = 0;
iLength = sIn.length();
if ( iLength <= 3 )
	{
	cout << "NO" <<endl;
	iFlag3 = 1;
	}
else
for ( i=0 ; i<iLength ; i++ )
	{
	if (  sIn[i] == 'A' && sIn[i+1] == 'B'  )
		{
		iFlag = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'B' && sIn[j+1] == 'A' )
				{
				cout << "YES" <<endl;
				iFlag = 0;
				iFlag3 =1;
				break;
				}
		if ( iFlag == 1 )
			cout << "NO" << endl;
		iFlag3 =1;
		break;

		}
	if (  sIn[i] == 'B' && sIn[i+1] == 'A'  )
		{
		iFlag2 = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'A' && sIn[j+1] == 'B' )
				{
				cout << "YES" <<endl;
				iFlag2 = 0;
				iFlag3 = 1;
				break;
				}
		if ( iFlag2 == 1 )
			cout << "NO" << endl;
		iFlag3=1;
		break;
		}

	}
	if ( iFlag3==0 )
		cout << "NO" <<endl;

}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
int iFlag1;
cin >> sIn;
int iFlag,iFlag2,iFlag3;
iFlag=iFlag2=iFlag3 = 0;
iLength = sIn.length();
if ( iLength <= 3 )
	{
	cout << "NO" <<endl;
	iFlag3 = 1;
	}
else
for ( i=0 ; i<iLength ; i++ )
	{
	if (  sIn[i] == 'A' && sIn[i+1] == 'B'  )
		{
		iFlag = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'B' && sIn[j+1] == 'A' )
				{
				cout << "YES" <<endl;
				iFlag = 0;
				iFlag3 =1;
				break;
				}
		/*
		if ( iFlag == 1 )
			cout << "NO" << endl;
		iFlag3 =1;
		break;
		*/
		}
	if (  sIn[i] == 'B' && sIn[i+1] == 'A'  )
		{
		iFlag2 = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'A' && sIn[j+1] == 'B' )
				{
				cout << "YES" <<endl;
				iFlag2 = 0;
				iFlag3 = 1;
				break;
				}
		/*
		if ( iFlag2 == 1 )
			cout << "NO" << endl;
		iFlag3=1;
		break;
		*/
		}
	if (iFlag == 1 && iFlag2 == 1 )
		{
		cout << "NO" <<endl;
		iFlag3 = 1;

		}
	}
	if ( iFlag3==0 )
		cout << "NO" <<endl;

}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
int iFlag1;
cin >> sIn;
int iFlag,iFlag2,iFlag3;
iFlag=iFlag2=iFlag3 = 0;
iLength = sIn.length();
if ( iLength <= 3 )
	{
	cout << "NO" <<endl;
	iFlag3 = 1;
	}
else
for ( i=0 ; i<iLength ; i++ )
	{
	if (  sIn[i] == 'A' && sIn[i+1] == 'B'  )
		{
		iFlag = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'B' && sIn[j+1] == 'A' )
				{
				cout << "YES" <<endl;
				iFlag = 0;
				iFlag3 =1;
				break;
				}

		if ( iFlag == 0 )
			break;

		}
	if (  sIn[i] == 'B' && sIn[i+1] == 'A'  )
		{
		iFlag2 = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'A' && sIn[j+1] == 'B' )
				{
				cout << "YES" <<endl;
				iFlag2 = 0;
				iFlag3 = 1;
				break;
				}

		if ( iFlag2 == 0 )
			break;

		}
	if (iFlag == 1 && iFlag2 == 1 )
		{
		cout << "NO" <<endl;
		iFlag3 = 1;

		}
	}
	if ( iFlag3==0 )
		cout << "NO" <<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
bool iFlag,iFlag2;
string sIn;
cin >> sIn;
int iFind,iFind2;
iFlag = iFlag2 = true;
if ( sIn.find("AB") == sIn.npos || sIn.find("BA") == sIn.npos )
	cout << "NO" << endl;
else
	{
	iFind = sIn.find("AB");
	if (  sIn.find("BA",iFind+2)==sIn.npos  )
		iFlag = false;
	iFind2 = sIn.find("BA");
	if 	( sIn.find("AB",iFind2+2)==sIn.npos   )
		iFlag2 = false;
	if ( iFlag  || iFlag2 )
		cout << "YES" << endl;
	else
		cout << "NO" <<endl;
	}
return 0;
}


#include <iostream>
#include <vector>
#define MAXN 100005
using namespace std;
int iBucketAB[MAXN];
int iBucketBA[MAXN];
int main()
{
string sIn;
int i,iLength;
int iFlag1;
cin >> sIn;
int iFlag,iFlag2,iFlag3;
iFlag=iFlag2=iFlag3 = 0;
iLength = sIn.length();
if ( iLength <= 3 )
	cout << "NO" <<endl;
else
for ( i=0 ; i<iLength ; i++ )
	{
	if (  sIn[i] == 'A' && sIn[i+1] == 'B'  )
		{
		iFlag = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'B' && sIn[j+1] == 'A' )
				{
				cout << "YES" <<endl;
				iFlag = 0;
				iFlag3 =1;
				break;
				}
		if ( iFlag == 1 )
			cout << "NO" << endl;
		iFlag3 =1;
		break;

		}
	if (  sIn[i] == 'B' && sIn[i+1] == 'A'  )
		{
		iFlag2 = 1;
		for ( int j=i+2 ; j<iLength ; j++ )
			if (  sIn[j] == 'A' && sIn[j+1] == 'B' )
				{
				cout << "YES" <<endl;
				iFlag2 = 0;
				iFlag3 = 1;
				break;
				}
		if ( iFlag2 == 1 )
			cout << "NO" << endl;
		iFlag3=1;
		break;
		}

	}
	if ( iFlag3==0 )
		cout << "NO" <<endl;

}


#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int iFlag,iFlag2,iFlag3;
string sIn;
cin >> sIn;
int iFind,iFind2;
iFind = sIn.find("AB");
iFind2 = sIn.find("BA");
iFlag = iFlag2 = 0;
if ( iFind == string::npos || iFind2 == string::npos )
	{
	cout << "NO" << endl;
	iFlag3 = 1;
	}
else
	{
	if (  sIn.find("BA",iFind+2)!=string::npos  )
		{
		if ( iFlag2 == 0 )
		cout << "YES" <<endl;
		iFlag = 1;
		}
	if 	( sIn.find("AB",iFind2+2)!=string::npos   )
		{
		if ( iFlag == 0 )
		cout <<"YES" <<endl;
		iFlag2= 1;
		}
	}
if ( iFlag!=1 && iFlag2!=1 && iFlag3!=1)
	cout << "NO" <<endl;
return 0;
}


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    string s;
    cin>>s;
    ll pos1 = s.find("AB");
    ll pos2 = s.find("BA");
    if(pos1!=-1 && s.find("BA",pos1+2)!=-1 || pos2!=-1 && s.find("AB",pos2+2)!=-1){cout<<"YES";}
    //else if(pos2!=-1 && s.find("AB",pos2+2)!=-1){cout<<"YES";}
    else cout<<"NO";

}

// Alhamdulillah.


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    char s[1000000];
    cin>>s;
    char *p,*q;
    p=strstr(s,"AB");
    q=strstr(s,"BA");
    if(p&&q)cout<<"YES";
    else cout<<"NO";

}

// Alhamdulillah.


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    int cnt=0,cnt1=0,cnt2=0;
    string s;
    cin>>s;
    for(ll i=0;i<s.size()-1;i++)
    {
        if(s[i]=='A'&& s[i+1]=='B' && s[i+2]=='A' && i<s.size()-2){cnt2=1;i+=3;}
        if(s[i]=='A'&& s[i+1]=='B'){cnt1=1;}
        if(s[i]=='B'&& s[i+1]=='A'){cnt=1;}
        if(cnt>0 && cnt1>0 || cnt>0 && cnt2>0 || cnt2>0 && cnt1>0){cout<<"YES";return 0;}
    }
    cout<<"NO";

}

// Alhamdulillah.


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    int cnt=0,cnt1=0,cnt2=0;
    string s;
    cin>>s;
    for(ll i=0;i<s.size()-1;i++)
    {
        if(s[i]=='A'&& s[i+1]=='B' && s[i+2]=='A' && i<s.size()-2){cnt2=1;i+=3;}
        if(s[i]=='B'&& s[i+1]=='A' && s[i+2]=='B' && i<s.size()-2){cnt2=1;i+=3;}
        if(s[i]=='A'&& s[i+1]=='B'){cnt1=1;}
        if(s[i]=='B'&& s[i+1]=='A'){cnt=1;}
        if(cnt>0 && cnt1>0 || cnt>0 && cnt2>0 || cnt2>0 && cnt1>0){cout<<"YES";return 0;}
    }
    cout<<"NO";

}

// Alhamdulillah.


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    int cnt=0,cnt1=0,cnt2=0;
    string s;
    cin>>s;
    for(ll i=0;i<s.size()-1;i++)
    {
        if(s[i]=='A'&& s[i+1]=='B' && s[i+2] && i<s.size()-2){cnt2=1;i+=3;}
        if(s[i]=='A'&& s[i+1]=='B'){cnt1=1;}
        if(s[i]=='B'&& s[i+1]=='A'){cnt=1;}
        if(cnt>0 && cnt1>0 || cnt>0 && cnt2>0 || cnt2>0 && cnt1>0){cout<<"YES";return 0;}
    }
    cout<<"NO";

}

// Alhamdulillah.


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    int cnt=0,cnt1=0,cnt2=0;
    string s;
    cin>>s;
    for(ll i=0;i<s.size()-1;i++)
    {
        if(s[i]=='A'&& s[i+1]=='B' && s[i+2]=='A' && i<s.size()-2){cnt2++;i+=3;}
        if(s[i]=='B'&& s[i+1]=='A' && s[i+2]=='B' && i<s.size()-2){cnt2++;i+=3;}
        if(s[i]=='A'&& s[i+1]=='B'){cnt1=1;}
        if(s[i]=='B'&& s[i+1]=='A'){cnt=1;}
        if(cnt>0 && cnt1>0 || cnt>0 && cnt2>0 || cnt2>0 && cnt1>0 || cnt2>1){cout<<"YES";return 0;}
    }
    cout<<"NO";

}

// Alhamdulillah.


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    int cnt=0,cnt1=0;
    string s;
    cin>>s;
    for(ll i=0;i<s.size()-1;i++)
    {
        if(s[i]=='A'&& s[i+1]=='B'){cnt1=1;i+=2;}
        if(s[i]=='B'&& s[i+1]=='A'){cnt=1;i+=2;}
        if((cnt+cnt1)%2==0 && (cnt+cnt1)>0){cout<<"YES";return 0;}
    }
    cout<<"NO";

}

// Alhamdulillah.


                        //بسم الله الرحمن الرحيم BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers vector,deque,list

#define vc    vector<char>
#define vi    vector<int>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

#define mps   map<string,string>
#define si    set<int>
#define sc    set<char>
#define sti   stack<int>
#define stc   stack<char>
#define msi   multiset<int>
#define ses "\n"

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    IOS
    string s;
    cin>>s;
    ll pos1 = s.find("AB");
    ll pos2 = s.find("BA");
    if(pos1!=-1 && s.find("BA",pos1+2)){cout<<"YES";}
    else if(pos2!=-1 && s.find("AB",pos2+2)){cout<<"YES";}
    else cout<<"NO";

}

// Alhamdulillah.


import java.util.*;
public class P2{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a==b){
                System.out.println("YES");
            }
            else if(a==1){
                System.out.println("NO");
            }
            else{
                if(a%2==1){
                    a--;
                }
                a+=(a/2);
                if(a>=b){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }
        }
    }
}


import java.util.*;
public class P2{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a==b){
                System.out.println("YES");
            }
            else if(a==1){
                System.out.println("NO");
            }
            else if(a==3 && (b==4 || b==5)){
                System.out.println("NO");
            }
            else{
                System.out.println("YES");
            }
        }
    }
}


import java.util.*;
public class P2{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a==b){
                System.out.println("YES");
            }
            else if(a==1){
                System.out.println("NO");
            }
            else if(a==2 && b>3){
                System.out.println("NO");
            }
            else if(a==3 && b>3){
                System.out.println("NO");
            }
            else{
                System.out.println("YES");
            }
        }
    }
}


import java.util.*;
public class P2{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a==b){
                System.out.println("YES");
            }
            else if(a==1 && b==2){
                System.out.println("YES");
            }
            else if(a==1 && b>2){
                System.out.println("YES");
            }
            else{
                if(a%2==1){
                    a--;
                }
                a+=(a/2);
                if(a>=b){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }
        }
    }
}


import java.util.*;
import java.io.*;
public class B{
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

		int t=Integer.parseInt(br.readLine());
		while(t-->0) {
			StringTokenizer st=new StringTokenizer(br.readLine());
			int x=Integer.parseInt(st.nextToken());
			int y=Integer.parseInt(st.nextToken());
			int control=x;
			int  cont=0;
			if(x==y||x>y)
				pw.append("YES\n");
			else {
				while(x!=y||x!=y+1) {
					if(x<=0)
						break;
					if(cont==10)
						break;
					if(x==control)
						cont++;
					if(x>1&&x%2==0)
						x=(x*3)/2;
					else if(x>1)
						x--;
					if(x==y||x>y)
						break;
				}
				if(x==y||x>y)
					pw.append("YES\n");
				else
					pw.append("NO\n");
			}
		}

		pw.flush();
		br.close();
		pw.close();
	}
}


import java.util.*;
import java.io.*;
public class B{
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

		int t=Integer.parseInt(br.readLine());
		while(t-->0) {
			StringTokenizer st=new StringTokenizer(br.readLine());
			double x=Double.parseDouble(st.nextToken());
			double y=Double.parseDouble(st.nextToken());
			double control=x;
			double cont=0;
			if(x==y||x>y)
				pw.append("YES\n");
			else {
				while(x!=y||x!=y+1) {
					if(x<=0)
						break;
					if(cont==10)
						break;
					if(x==control)
						cont++;
					if(x>1&&x%2==0)
						x=(x*3)/2;
					else if(x>1)
						x--;
					if(x==y||x>y)
						break;
				}
				if(x==y||x>y)
					pw.append("YES\n");
				else
					pw.append("NO\n");
			}
		}

		pw.flush();
		br.close();
		pw.close();
	}
}