#include <bits/stdc++.h>
using namespace std;
string s;
int ans = 0;
int main() {
  cin >> s;
  int z = s.size();
  for (int i = 0; i < z; ++i) {
    if (s[i] == 'Q') {
      for (int j = i + 1; j < z; ++j) {
        if (s[j] == 'A') {
          for (int k = j + 1; k < z; ++k) {
            if (s[k] == 'Q') {
              ans++;
            }
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
