#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int ans = 0;
  int qs = 0;
  int as = 0;
  for (auto x : s) {
    if (x == 'Q') {
      ans += as;
      ++qs;
    } else if (x == 'A')
      as += qs;
  }
  cout << ans << endl;
  return 0;
}
