#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string tmp = "QAQ";
  int count = 0;
  for (int i = 0; i < s.length(); i++) {
    if (tmp[0] == s[i]) {
      for (int j = i + 1; j < s.length(); j++) {
        if (tmp[1] == s[j]) {
          for (int k = j + 1; k < s.length(); k++) {
            if (tmp[2] == s[k]) {
              count++;
            }
          }
        }
      }
    }
  }
  cout << count << endl;
}
