#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long a = 0, q = 0, res = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == 'Q') {
      q++;
      res += a;
    } else if (s[i] == 'A')
      a += q;
  }
  cout << res << endl;
}
