#include <bits/stdc++.h>
int main(void) {
  int len;
  char str[101] = "\0";
  int dp[3] = {0, 0, 0};
  gets(str);
  len = strlen(str);
  for (int i = 0; i < len; i++) {
    if (str[i] != 'Q' && str[i] != 'A') continue;
    if (str[i] == 'Q') {
      dp[2] += dp[1];
      dp[0]++;
    }
    if (str[i] == 'A') {
      dp[1] += dp[0];
    }
  }
  printf("%d", dp[2]);
  return 0;
}
