#include <bits/stdc++.h>
using namespace std;
int main() {
  int stp = 0, srt = 0, q = 0, a = 0;
  string str, s;
  cin >> str;
  for (int i = 0; i < str.length(); i++) {
    for (int j = i + 1; j < str.length(); j++) {
      for (int k = j + 1; k < str.length(); k++) {
        if (str[i] == 'Q' && str[j] == 'A' && str[k] == 'Q') {
          a++;
        }
      }
    }
  }
  cout << a;
}
