#include <bits/stdc++.h>
using namespace std;
int findQ(const string &input, int pos, int len) {
  int count = 0;
  for (int i = pos; i < len; i++)
    if (input[i] == 'Q') {
      count++;
    }
  return count;
}
int findAandQ(const string &input, int pos, int len) {
  int count = 0, total = 0;
  for (int i = pos; i < len; i++) {
    if (input[i] == 'A') {
      count = findQ(input, i, len);
      total += count;
    }
  }
  return total;
}
int main() {
  string input;
  int count = 0, total = 0, i;
  getline(cin, input);
  int len = input.length();
  for (i = 0; i < len; i++) {
    if (input[i] == 'Q') {
      count = findAandQ(input, i, len);
      total += count;
    }
  }
  cout << total;
}
