#include <bits/stdc++.h>
using namespace std;
char s[500];
int main() {
  int i, j;
  int tmp1, tmp2, ans = 0;
  scanf("%s", s);
  for (i = 0; i < strlen(s); i++) {
    tmp1 = tmp2 = 0;
    if (s[i] == 'A') {
      for (j = i - 1; j >= 0; j--)
        if (s[j] == 'Q') tmp1++;
      for (j = i + 1; j < strlen(s); j++)
        if (s[j] == 'Q') tmp2++;
    }
    ans += tmp1 * tmp2;
  }
  printf("%d\n", ans);
  return 0;
}
