#include <bits/stdc++.h>
using namespace std;
int main() {
  char myString[100];
  cin.getline(myString, 100 + 5);
  int cont = 0;
  for (int index = 0; index < 100 + 5; index++) {
    if (myString[index] == 'Q') {
      for (int index2 = index; index2 < 100 + 5; index2++) {
        if (myString[index2] == 'A') {
          for (int index3 = index2; index3 < 100 + 5; index3++) {
            if (myString[index3] == 'Q') {
              cont++;
            }
          }
        }
      }
    }
  }
  cout << cont;
  return 0;
}
