#include <bits/stdc++.h>
using namespace std;
const int mn = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int ag = 0, n = s.length();
  for (int i = 0; i < n; i += 1) {
    if (s[i] == 'Q')
      for (int j = i + 1; j < n; j += 1) {
        if (s[j] == 'A')
          for (int k = j + 1; k < n; k += 1) {
            if (s[k] == 'Q') ag += 1;
          }
      }
  }
  cout << ag;
  return 0;
}
