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