#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int countQtotal = 0, countQ = 0;
  int N;
  int ans = 0;
  cin >> S;
  N = S.length();
  for (int i = 0; i < N; i++) {
    if (S[i] == 'Q') countQtotal++;
  }
  for (int i = 0; i < N; i++) {
    if (S[i] == 'Q') countQ++;
    if (S[i] == 'A') {
      ans = ans + countQ * (countQtotal - countQ);
    }
  }
  cout << ans << endl;
  return 0;
}
