#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long int q = 0, a = 0, qa = 0, qaq = 0;
  for (long long int i = 0; i < s.length(); ++i) {
    if (s[i] == 'Q') {
      ++q;
      qaq += qa;
    } else if (s[i] == 'A') {
      qa += q;
      ++a;
    }
  }
  cout << qaq << endl;
}
