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