#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int t = power(a, b / 2);
  return (b % 2) ? t * t * a : t * t;
}
void test_case() {
  string s;
  cin >> s;
  long long int cnt = 0;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] == 'Q') {
      for (long long int j = i + 1; j < s.length(); j++) {
        if (s[j] == 'A') {
          for (long long int k = j + 1; k < s.length(); k++) {
            if (s[k] == 'Q') {
              cnt++;
            }
          }
        }
      }
    }
  }
  cout << cnt << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  cout << fixed << setprecision(10);
  long long int t = 1;
  while (t--) {
    test_case();
  }
  return 0;
}
