#include <bits/stdc++.h>
using namespace std;
int Abf[102];
int main() {
  int ans = 0;
  string S;
  cin >> S;
  int Qbf = 0;
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == 'Q') Qbf++;
    if (S[i] == 'A') Abf[i] = Qbf;
  }
  int Qaf = 0;
  for (int i = S.size() - 1; i >= 0; --i) {
    if (S[i] == 'Q') Qaf++;
    if (S[i] == 'A') {
      ans += Abf[i] * Qaf;
    }
  }
  cout << ans;
  return 0;
}
