#include <bits/stdc++.h>
using namespace std;
int n, ans = 0, qb = 0, q[128] = {0};
char s[128];
int main() {
  cin >> s;
  n = (int)strlen(s);
  for (int i = 0; i < n; i++) q[i + 1] = (s[i] == 'Q') + q[i];
  for (int i = n - 1; i > -1; i--)
    if (s[i] == 'Q')
      qb++;
    else if (s[i] == 'A')
      ans += q[i] * qb;
  cout << ans << endl;
  return 0;
}
