#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[200];
  int s1, s2, len, sum;
  s1 = 0;
  s2 = 0;
  sum = 0;
  cin >> a;
  len = strlen(a);
  for (int i = 0; i < len; i++) {
    s1 = 0;
    s2 = 0;
    if (a[i] == 'A') {
      for (int x = i; x >= 0; x--)
        if (a[x] == 'Q') s1++;
      for (int y = i; y < len; y++)
        if (a[y] == 'Q') s2++;
    }
    sum += (s1 * s2);
  }
  cout << sum << endl;
}
