#include using namespace std; typedef long long ll; int main() { string s; cin >> s; int acnt = 0; int n = s.size(); for (int i = 0; i < n; ++i) { if (s[i] == 'A')acnt++; } vector b; vector a; for (int i = 0; i < n; ++i) { if (s[i] == 'B' && i < acnt) b.push_back(i); if (s[i] == 'A' && i >= acnt) a.push_back(i); } int ans = 0; int m = a.size(); for (int i = 0; i < m; ++i) { ans += a[i] - b[i]; } cout << ans << '\n'; return 0; }