#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  int num = 0, check = 0;
  char b[128];
  cin >> a;
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == 'Q' || a[i] == 'A') {
      b[num] = a[i];
      num++;
    }
  }
  for (int i = 0; i <= num; i++) {
    for (int j = i + 1; j <= num; j++) {
      for (int k = j + 1; k <= num; k++) {
        if (b[i] == 'Q' && b[j] == 'A' && b[k] == 'Q') {
          check++;
        }
      }
    }
  }
  cout << check;
}
