#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long int len = s.length();
  long long int cnt = 0;
  for (long long int i = 0; i < len; i++) {
    if (s[i] == 'Q') {
      cnt++;
    }
  }
  long long int suffixes = cnt;
  long long int prefixes = 0;
  long long int ans = 0;
  for (long long int j = 0; j < len; j++) {
    if (s[j] == 'Q') {
      prefixes++;
      suffixes--;
    }
    if (s[j] == 'A') {
      ans += prefixes * suffixes;
    }
  }
  cout << ans << endl;
  return 0;
}
