#include using namespace std; typedef long long ll; typedef pair PI; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; if (s.size() == 1) { cout << 0 << endl; } int a = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'A') a++; } int ans = 0; int pos = 0; while (true) { bool flag = false; for (int i = pos; i < s.size(); i++) { if (s[i] == 'B' && s[i+1] == 'A') { s[i] = 'A'; s[i+1] = 'B'; ans++; break; } } pos = s.find('B') - 1; //cout << s << pos << endl; if (pos + 1 == a) { break; } } cout << ans << endl; return 0; }