#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int n = s.size();
  set<int> s1, s2;
  for (int i = 0; i + 1 < n; i++) {
    if (s.substr(i, 2) == "AB") {
      s1.insert(i);
    }
  }
  for (int i = 0; i + 1 < n; i++) {
    if (s.substr(i, 2) == "BA") {
      s2.insert(i);
    }
  }
  bool found = false;
  set<int>::iterator it;
  for (it = s1.begin(); it != s1.end(); it++) {
    bool first = false, second = false, third = false;
    if (s2.find(*it) != s2.end()) {
      s2.erase(*it);
      first = true;
    }
    if (s2.find(*it + 1) != s2.end()) {
      s2.erase(*it + 1);
      second = true;
    }
    if (s2.find(*it - 1) != s2.end()) {
      s2.erase(*it - 1);
      third = true;
    }
    if (s2.size()) {
      found = true;
      break;
    }
    if (first) {
      s2.insert(*it);
    }
    if (second) {
      s2.insert(*it + 1);
    }
    if (third) {
      s2.insert(*it - 1);
    }
  }
  if (found)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
