#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void solve() {
  string s;
  cin >> s;
  ll len = s.length();
  ll qcount = 0;
  for (char c : s) {
    if (c == 'Q') qcount++;
  }
  ll q = 0;
  ll total = 0;
  for (char c : s) {
    if (c == 'Q') q++;
    if (c == 'A') {
      total += q * (qcount - q);
    }
  }
  cout << total << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll T = 1;
  while (T--) solve();
}
