#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  long long int n = s.size();
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] != 'Q') continue;
    for (long long int j = i + 1; j < n; j++) {
      if (s[j] != 'A') continue;
      for (long long int k = j + 1; k < n; k++) {
        if (s[k] == 'Q') ans++;
      }
    }
  }
  cout << ans;
}
