#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  string ss = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'Q' || s[i] == 'A') {
      ss += s[i];
    }
  }
  while (ss[ss.size() - 1] == 'A') {
    ss.erase(ss.size() - 1, 1);
  }
  while (ss[0] == 'A') {
    ss.erase(0, 1);
  }
  int c_q = 0;
  int c_a = 0;
  for (int i = 0; i < ss.size(); i++) {
    if (ss[i] == 'Q') {
      c_q++;
    } else if (ss[i] == 'A') {
      c_a++;
    }
  }
  int ans = 0;
  for (int i = 0; i < ss.size(); i++) {
    for (int j = i + 1; j < ss.size(); j++) {
      for (int k = j + 1; k < ss.size(); k++) {
        string tmp = "";
        tmp += ss[i];
        tmp += ss[j];
        tmp += ss[k];
        if (tmp == "QAQ") {
          ans++;
        }
      }
    }
  }
  cout << ans;
}
