#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; int res = 0; for (int i = (int)S.size() - 1; i > -1; i--) { if (S[i] == 'A') { for (int j = i - 1; j > -1; j--) { if (S[j] == 'B') { swap(S[i], S[j]); res += i - j; break; } } } } cout << res << '\n'; return 0; }