#include #include using namespace std; int main() { string str; cin >> str; if (str.size() == 1) { cout << 0; return 0; } int now = 0; int count = 0; while(now!=str.size()-1){ if (str[now] == 'A') { now++; continue; } else if (str[now] == 'B') { if (str[now + 1] == 'A') { char tmp = str[now]; str[now] = str[now + 1]; str[now + 1] = tmp; now = 0; count++; continue; } now++; } } cout << count; return 0; }