#include <bits/stdc++.h>
using namespace std;
int main() {
  string p;
  cin >> p;
  int ans = 0;
  for (int i = 0; i < p.size(); i++) {
    if (p[i] != 'Q') continue;
    for (int j = i + 1; j < p.size(); j++) {
      if (p[j] != 'A') continue;
      for (int k = j + 1; k < p.size(); k++) {
        if (p[k] != 'Q') continue;
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
