#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int l = s.length();
  int a[l];
  a[0] = 0;
  int ans = 0;
  for (int i = 1; i < l; i++) {
    a[i] = 0;
    if (s[i] == 'Q' || s[i] == 'A') {
      for (int j = 0; j < i; j++) {
        if (s[i] == 'A' && s[j] == 'Q')
          a[i] = a[j] + 1;
        else if (s[i] == 'Q' && s[j] == 'Q')
          a[i] = a[j] + 1;
        else if (s[i] == 'Q' && s[j] == 'A') {
          a[i] = a[j];
          ans += a[j];
        }
      }
    }
  }
  cout << ans;
}
