#include #include #include using namespace std; int main() { string s; cin >> s; int cnt = 0, ans = 0; for (char c: s) { if (c == 'A') ans += cnt; if (c == 'B') cnt++; } cout << ans << endl; return 0; }