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