#include <bits/stdc++.h>
using namespace std;
long long n, m, a[210101], asdaf, k, asdasd, ans, suf[210001], pref[210001], mx,
    b[210001];
map<long long, long long> us;
vector<long long> v;
int main() {
  long long t24 = 1;
  for (long long qwe = 1; qwe <= t24; qwe++) {
    long long sum = 0, f = 0, q1 = 0, l = 0, kol = 0, q = 1e9, kol1 = 0;
    string s;
    cin >> s;
    ans = 0;
    for (int i = 0; i < s.size(); i++) {
      pref[i] = pref[i - 1];
      if (s[i] == 'Q') pref[i]++;
    }
    for (int i = s.size() - 1; i >= 0; i--) {
      suf[i] = suf[i + 1];
      if (s[i] == 'Q') suf[i]++;
    }
    for (int i = 0; i < s.size(); i++)
      if (s[i] == 'A') ans += pref[i] * suf[i];
    cout << ans << endl;
  }
  return 0;
}
