#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string str;
  int total = 0;
  cin >> str;
  if (str.length() < 3) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < str.length() - 2; i++) {
    for (int j = i + 1; j < str.length() - 1; j++) {
      for (int k = j + 1; k < str.length(); k++) {
        if (str[i] == 'Q' && str[j] == 'A' && str[k] == 'Q') total++;
      }
    }
  }
  cout << total << endl;
}
