#include <bits/stdc++.h>
using namespace std;
const int MAX = 110;
int lf[MAX], rg[MAX];
char s[MAX];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  memset(lf, 0, sizeof lf);
  memset(rg, 0, sizeof rg);
  lf[0] = (s[0] == 'Q');
  for (int i = 1; i < n; ++i) {
    lf[i] = lf[i - 1] + (s[i] == 'Q');
  }
  rg[n - 1] = (s[n - 1] == 'Q');
  for (int i = n - 2; i >= 0; --i) {
    rg[i] = rg[i + 1] + (s[i] == 'Q');
  }
  int ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    if (s[i] == 'A') {
      ans += (rg[i + 1] * lf[i - 1]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
