#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  string t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'Q' || s[i] == 'A') t += s[i];
  }
  int x = -1, y = -1;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == 'Q') {
      x = i;
      break;
    }
  }
  for (int i = t.size() - 1; i >= 0; i--) {
    if (t[i] == 'Q') {
      y = i;
      break;
    }
  }
  long long count = 0;
  if (x == -1 || y == -1 || x == y)
    cout << 0 << endl;
  else {
    while (x < y) {
      if (t[x] != 'Q')
        x++;
      else {
        int l = y;
        while (l > x) {
          if (t[l] != 'Q')
            l--;
          else {
            for (int i = x + 1; i < l; i++) {
              if (t[i] == 'A') count++;
            }
            l--;
          }
        }
        x++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
