#include <bits/stdc++.h>
long long n, a, b, c, x, y, z, i, j, k, len;
int main() {
  char s[101];
  int cnt[101] = {0};
  scanf("%s", s);
  char *p = s;
  i = 0;
  int sum = 0;
  while (*p) {
    if (*p == 'Q') {
      cnt[i]++;
      c++;
    } else if (*p == 'A') {
      cnt[++i] = c;
    }
    p++;
  }
  for (j = 0; j <= i; j++) {
    sum += cnt[j] * (c - cnt[j]);
  }
  printf("%d\n", sum);
}
