#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  string str = "";
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'Q' || s[i] == 'A') str += s[i];
  }
  long x = 0;
  s = str;
  long l = 0, m = 0;
  for (int i = 0; i < str.length(); ++i)
    if (str[i] == 'Q') l++;
  for (int i = str.length(); i >= 0; --i) {
    if (s[i] == 'A') {
      x += (l * m);
    }
    if (s[i] == 'Q') {
      l--;
      m++;
    }
  }
  cout << x << endl;
  return 0;
}
