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