#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n;
  int Q[100], A[100];
  int i, j = 0, k = 0, l, m;
  int countQAQ = 0;
  cin >> s;
  n = s.length();
  for (i = 0; i < n; i++) {
    if (s[i] == 'Q') {
      Q[j] = i;
      j = j + 1;
    }
    if (s[i] == 'A') {
      A[k] = i;
      k = k + 1;
    }
  }
  for (m = 0; m < j; m++) {
    for (i = 1; i < j; i++) {
      for (l = 0; l < k; l++) {
        if (A[l] > Q[m] && A[l] < Q[i]) {
          countQAQ = countQAQ + 1;
        }
      }
    }
  }
  cout << countQAQ << endl;
  return 0;
}
