#include using namespace std; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long lcm(long long x, long long y) { if (x == 0 || y == 0) return 0; return x / gcd(x, y) * y; } int main() { string s; cin >> s; int n = s.size(); string ss = s; sort(ss.begin(), ss.end()); int cnt = 0; while (ss != s) { for (int i = 0; i < n - 1; i++) { if (s[i] == 'B' and s[i + 1] == 'A') { cnt++; swap(s[i], s[i + 1]); } } /* for (int i = n - 1; i < 0; i--) { if (s[i] == 'A' and s[i - 1] == 'B') { cnt++; swap(s[i], s[i - 1]); } } */ } cout << cnt << endl; }