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