#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n = str.size();
  int freq[n];
  int total = 0;
  for (int i = 0; i < n; i++)
    if (str[i] == 'Q') {
      total += 1;
      freq[i] = total;
    } else
      freq[i] = total;
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'A') {
      ans += (freq[i] * (total - freq[i]));
    }
  }
  cout << ans << endl;
  return 0;
}
