#include #include using namespace std; int main() { string s; cin >> s; int cnt = 0; int len = s.size(); for (int x = 0; x < len - 1; x++) { for (int y = x; y < len - 1; y++) { if (s[y] != 'B' || s[y + 1] != 'A') { continue; } char tmp = s[y]; s[y] = s[y + 1]; s[y + 1] = tmp; cnt++; } } cout << cnt << endl; return 0; }