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