#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  int c = 0;
  cin >> x;
  int n = x.length();
  for (int i = 0; i < n; i++)
    if (x[i] == 'Q')
      for (int j = i + 1; j < n; j++)
        if (x[j] == 'A')
          for (int f = j + 1; f < n; f++)
            if (x[f] == 'Q') c++;
  cout << c;
}
