#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long res = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      int L = 0, R = 0;
      for (int j = i - 1; j >= 0; j--)
        if (s[j] == 'Q') L++;
      for (int j = i + 1; s[j]; j++)
        if (s[j] == 'Q') R++;
      res += L * R;
    }
  }
  cout << res;
  return 0;
}
