#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const double eps = 1e-8;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int maxn = 110;
int cnt[maxn];
char str[maxn];
bool isA[maxn];
int main() {
  memset(cnt, 0, sizeof(cnt));
  memset(isA, 0, sizeof(isA));
  scanf("%s", str);
  int Qnum = 0;
  for (int i = 0; i < strlen(str); i++) {
    if (str[i] == 'Q')
      ++Qnum;
    else if (str[i] == 'A') {
      isA[i] = 1;
      cnt[i] = Qnum;
    }
  }
  int ans = 0;
  for (int i = 0; i < strlen(str); i++) {
    if (isA[i] == 1) {
      ans += cnt[i] * (Qnum - cnt[i]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
