#include <bits/stdc++.h>
using namespace std;
string s;
int d;
int main() {
  if (0) {
    freopen("project1.inp", "r", stdin);
    freopen("project1.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin >> s;
  for (int i = 0; i < s.size(); ++i)
    for (int j = i + 1; j < s.size(); ++j)
      for (int l = j + 1; l < s.size(); ++l)
        if (s[i] == 'Q' && s[j] == 'A' && s[l] == 'Q') ++d;
  cout << d;
  return 0;
}
