#include <bits/stdc++.h>
using ll = long long;
using namespace std;
string s;
int n;
int rec(int idx, int pre) {
  if (idx == n) return 0;
  int ret = 0;
  if (s[idx] == 'Q' && pre == 0)
    ret += rec(idx + 1, pre + 1);
  else if (s[idx] == 'A' && pre == 1)
    ret += rec(idx + 1, pre + 1);
  else if (s[idx] == 'Q' && pre == 2)
    ret++;
  ret += rec(idx + 1, pre);
  return ret;
}
int main() {
  cin >> s;
  n = s.size();
  cout << rec(0, 0) << endl;
  return 0;
}
