#include <bits/stdc++.h>
using namespace std;
char s[200];
int n, p[200], q[200];
int main() {
  cin >> s + 1;
  int len = strlen(s + 1);
  for (int i = 1; i <= len; i++) p[i] = p[i - 1] + (s[i] == 'Q');
  for (int i = len; i >= 1; i--) q[i] = q[i + 1] + (s[i] == 'Q');
  int ans = 0;
  for (int i = 1; i <= len; i++)
    if (s[i] == 'A') ans += p[i] * q[i];
  cout << ans;
  return 0;
}
