#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  vector<int> qcnt(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'Q') {
      cnt++;
    }
    qcnt[n - i - 1] = cnt;
  }
  int ans = 0;
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    if (s[i] == 'Q') {
      for (int j = i + 1; j < n; j++) {
        if (s[j] == 'A') {
          ans += qcnt[j];
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
