#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k = 0, l = 0, ans = 0, m, t, a[100005], b[2005] = {0}, c[35];
string second;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> second;
  for (i = 0; i < second.size(); i++) {
    if (second[i] == 'A') {
      long long k = 0, l = 0;
      for (j = 0; j < i; j++)
        if (second[j] == 'Q') k++;
      for (j = i + 1; j < second.size(); j++)
        if (second[j] == 'Q') l++;
      ans += (k * l);
    }
  }
  cout << ans << endl;
}
