#include <bits/stdc++.h>
using namespace std;
signed main() {
  string a;
  cin >> a;
  int n = a.size();
  int b[n];
  if (a[0] == 'Q')
    b[0] = 1;
  else
    b[0] = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] == 'Q') {
      b[i] = b[i - 1] + 1;
    } else {
      b[i] = b[i - 1];
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 'A') {
      int p;
      if (i == 0)
        p = 0;
      else
        p = b[i - 1];
      int q;
      if (i == n - 1)
        q = 0;
      else
        q = b[n - 1] - b[i];
      ans += (p * q);
    }
  }
  cout << ans << "\n";
}
