#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  cin >> s;
  int i, j, k, countq1, countq2, res = 0;
  int n = s.length();
  for (i = 0; i < n; i++) {
    countq1 = 0;
    countq2 = 0;
    if (s[i] == 'A') {
      for (j = i; j >= 0; j--) {
        if (s[j] == 'Q') countq1++;
      }
      for (k = i; k < n; k++) {
        if (s[k] == 'Q') countq2++;
      }
    }
    res += countq2 * countq1;
  }
  cout << res << endl;
  return 0;
}
