#include #include using namespace std; int main(){ string S; cin >> S; int N = S.size(); int ans = 0; for (int i = 0; i < N; i++){ for (int j = 0; j < N - 1; j++){ if (S[j] == 'B' && S[j + 1] == 'A'){ ans++; swap(S[j], S[j + 1]); } } } cout << ans << endl; }