#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[101], b[101];
  int i, l, j = 0, c = 0, k, p;
  cin >> a;
  l = strlen(a);
  for (i = 0; i < l; i++) {
    if (a[i] == 'Q' || a[i] == 'A') {
      b[j] = a[i];
      j++;
    }
  }
  for (i = 0; i < j; i++) {
    if (b[i] == 'Q') {
      for (k = i + 1; k < j; k++) {
        if (b[k] == 'A') {
          for (p = k + 1; p < j; p++) {
            if (b[p] == 'Q') c++;
          }
        }
      }
    }
  }
  cout << c << endl;
  return 0;
}
