#include <bits/stdc++.h>
using namespace std;
string s;
string m = "";
int main() {
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'Q' || s[i] == 'A') m += s[i];
  }
  if (m.length() < 3) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < m.length(); i++)
    for (int j = i + 1; j < m.length(); j++)
      for (int k = j + 1; k < m.length(); k++)
        if (m[i] == 'Q' && m[j] == 'A' && m[k] == 'Q') count++;
  cout << count << endl;
  return 0;
}
