#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  vector<int> dp(s.length() + 1, 0);
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == 'Q')
      dp[i] = dp[i + 1] + 1;
    else
      dp[i] = dp[i + 1];
  }
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'Q') {
      for (int j = i + 1; j < s.length(); j++) {
        if (s[j] == 'A') {
          ans += dp[j];
        }
      }
    }
  }
  cout << ans << endl;
}
