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