#include <bits/stdc++.h>
using namespace std;
vector<int> Q, A;
int main() {
  string s;
  cin >> s;
  int counter = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'Q')
      Q.push_back(i);
    else if (s[i] == 'A')
      A.push_back(i);
  }
  for (int i = 0; i < A.size(); i++) {
    int smallerCount = 0, biggerCount = 0;
    for (int j = 0; j < Q.size(); j++) {
      if (Q[j] < A[i]) smallerCount++;
      if (Q[j] > A[i]) biggerCount++;
    }
    counter += smallerCount * biggerCount;
  }
  cout << counter;
}
