#include <bits/stdc++.h>
using namespace std;
char s[105];
int n, sl;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.getline(s, 105);
  n = strlen(s);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      for (int l = j + 1; l < n; l++)
        if (s[i] == 'Q' and s[j] == 'A' and s[l] == 'Q') sl++;
  cout << sl;
  return 0;
}
