#include #include #include using namespace std; int main(void){ string s; cin >> s; int ans = 0; int c = 0; for(int i = 0; i < s.length(); i++){ if(s[i] == 'A') ans += c; else c++; } cout << ans << endl; return 0; }