#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair pii; typedef tuple t3; using namespace std; map> g; map color; int main() { string s; cin >> s; int a = 0; vector v; const char A = 'A'; const char B = 'B'; int n = (int)s.length(); for(int i = 0;i < n;i++) { v.push_back(s[i]); if(s[i] == A) { a++; } } int count = 0; for(int i = 0;i < a;i++) { if(v[i] != A) { for(int j = i + 1;j < n;j++) { if(v[j] == A) { count += j-i; v[i] = A; v[j] = B; break; } } } } cout << count << endl; return 0; }