#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int num = 0, num1, num2;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      num1 = 0;
      for (int j = 0; j < i; j++)
        if (s[j] == 'Q') num1++;
      num2 = 0;
      for (int j = i + 1; j < s.size(); j++)
        if (s[j] == 'Q') num2++;
      num += (num1 * num2);
    }
  }
  cout << num;
  return 0;
}
