#include <bits/stdc++.h>
using namespace std;
int main() {
  int len = 0, res, ans = 0, c = 0;
  int r[101];
  string str;
  cin >> str;
  len = str.length();
  r[len] = 0;
  for (int i = len - 1; i >= 0; i--) {
    if (str[i] == 'Q')
      r[i] = r[i + 1] + 1;
    else {
      r[i] = r[i + 1];
    }
  }
  if (str[0] == 'Q') c = 1;
  ans = 0;
  for (int i = 1; i < len; i++) {
    if (str[i] == 'A') {
      ans += (c * r[i + 1]);
    } else if (str[i] == 'Q') {
      c++;
    }
  }
  cout << ans << endl;
  return 0;
}
