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