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