#include <bits/stdc++.h>
using namespace std;
const int MAX = 2005;
const long long MOD = 1e9 + 7;
const double PI = acos(-1.0);
char str[MAX];
int l[MAX];
int r[MAX];
int main() {
  scanf("%s", str);
  int len = strlen(str);
  long long ans = 0;
  if (str[0] == 'Q') l[0] = 1;
  for (int i = 1; i < len; i++) {
    l[i] = l[i - 1];
    if (str[i] == 'Q') l[i]++;
  }
  if (str[len - 1] == 'Q') r[len - 1] = 1;
  for (int i = len - 2; i >= 0; i--) {
    r[i] = r[i + 1];
    if (str[i] == 'Q') r[i]++;
  }
  for (int i = 0; i < len; i++) {
    if (str[i] == 'A') {
      ans += l[i] * r[i];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
