#include <bits/stdc++.h>
using namespace std;
int main() {
  string s = "";
  char c1, c2, c3;
  int temp = 0;
  cin >> s;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'Q') {
      c1 = 'Q';
      for (int j = i; j < s.length(); ++j) {
        if (s[j] == 'A') {
          c2 = 'QA';
          for (int k = j; k < s.length(); ++k) {
            if (s[k] == 'Q') {
              c3 = 'QAQ';
              temp++;
            }
          }
        }
      }
    }
  }
  cout << temp;
  return 0;
}
