#include #include #include #include #include #include #include #include #define AS(a) (sizeof(a)/sizeof(a[0])) using namespace std; long long int MOD = 1000000007; long long int INF = 1000000007; int main() { string s; cin >> s; int count = 0; while(1) { bool b = true; for(int i = 1; i < s.length(); i++) { if(s[i-1] == 'B' && s[i] == 'A') { count++; s[i-1] = 'A'; s[i] = 'B'; b = false; break; } } if(b) break; } cout << count << endl; }