#include <bits/stdc++.h>
char str[200];
int len, sum;
int main() {
  while (~scanf("%[^\n]%*c%n", &str, &len)) {
    sum = 0;
    for (int i = 0; i < len; i++) {
      if (str[i] == 'Q') {
        for (int j = i + 1; j < len; j++) {
          if (str[j] == 'Q') {
            for (int k = i + 1; k < j; k++) {
              if (str[k] == 'A') sum++;
            }
          }
        }
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}
