#include using namespace std; typedef signed long long ll; #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define SIZE(array) (sizeof(array) / sizeof(array[0])) long mod = 1000000007L; auto cmp = [](pair> const & a, pair> const & b) { return a.second.second < b.second.second; }; signed main() { string s; cin >> s; int ap = 0; int cost = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'A') { cost += i - ap; ap ++; } } cout << cost << endl; }