#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  char s[105];
  cin >> s;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == 'Q')
      for (int j = i + 1; j < strlen(s); j++) {
        if (s[j] == 'A')
          for (int k = j + 1; k < strlen(s); k++)
            if (s[k] == 'Q') n++;
      }
  }
  cout << n << endl;
  return 0;
}
