#include <bits/stdc++.h>
 
using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int res = 0;
    int pos = 0;
    int n = s.length();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='A')
        {
            res += (i - pos);
            pos++;
        }
    }

    cout << res << '\n';
    return 0;
}