#include <bits/stdc++.h>
using namespace std;
int QAQsub(int pos, string s, int state) {
  if (pos >= s.length()) {
    return 0;
  }
  int cnt = 0;
  for (int i = pos; i < int(s.length()); i++) {
    if (state == 0 and s[i] == 'Q') {
      cnt += QAQsub(i + 1, s, state + 1);
    } else if (state == 1 and s[i] == 'A') {
      cnt += QAQsub(i + 1, s, state + 1);
    } else if (state == 2 and s[i] == 'Q') {
      cnt++;
    }
  }
  return cnt;
}
int main() {
  string s;
  cin >> s;
  cout << QAQsub(0, s, 0) << "\n";
  return 0;
}
