#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k = 0;
  cin >> s;
  while (k < s.size())
    if (s[k] != 'Q' && s[k] != 'A')
      s.erase(k, 1);
    else
      k++;
  int x = 0, y = 0, ans = 0;
  for (int k = 0; k < s.size(); k++)
    if (s[k] == 'A') {
      for (int i = 0; i < k; i++)
        if (s[i] == 'Q') x++;
      for (int i = s.size() - 1; i > k; i--)
        if (s[i] == 'Q') y++;
      ans += x * y;
      x = y = 0;
    }
  cout << ans;
  return 0;
}
