#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  string str;
  int n, q = 0, a = 0, ans = 0;
  cin >> str;
  n = str.length();
  int arr[n + 5];
  for (int i = 0; i < n; i++) {
    arr[i] = str[i];
    if (str[i] == 'Q')
      q++;
    else if (str[i] == 'A')
      a++;
  }
  if (q == n || q == 0 || q == 1)
    cout << 0 << "\n";
  else if (a == n || a == 0)
    cout << 0 << "\n";
  else {
    for (int i = 0; i < n; i++) {
      if (arr[i] == 'Q') {
        for (int j = i + 1; j < n; j++) {
          if (arr[j] == 'A') {
            for (int k = j + 1; k < n; k++) {
              if (arr[k] == 'Q') ans++;
            }
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
