#include <bits/stdc++.h>
using namespace std;
char s[105];
int a[105];
int main() {
  cin >> s;
  int idx = -1;
  for (int i = 0; s[i]; ++i)
    if (s[i] == 'A' || s[i] == 'Q') a[++idx] = s[i];
  int cnt = 0;
  for (int i = 0; i <= idx; ++i) {
    if (a[i] != 'Q') continue;
    for (int j = i + 1; j <= idx; ++j) {
      if (a[j] != 'A') continue;
      for (int k = j + 1; k <= idx; ++k)
        if (a[k] == 'Q') ++cnt;
    }
  }
  cout << cnt;
  return 0;
}
