#include <bits/stdc++.h>
using namespace std;
string en = "\n";
string sp = " ";
string t = "hello";
string Y = "YES\n";
string N = "NO\n";
bool isprm(long long a) {
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
bool palin(string a) {
  for (int i = 0; i < a.size(); i++) {
    if (a.at(i) != a.at(a.size() - i - 1)) return 0;
  }
  return 1;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
long long bpow(long long a, long long b) {
  if (b == 0) return 1;
  long long r = bpow(a, b / 2);
  if (b % 2)
    return r * r * a;
  else
    return r * r;
}
long long binpow(long long a, long long b) {
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a;
    a = a * a;
    b >>= 1;
  }
  return r;
}
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long r = 1;
  while (b > 0) {
    if (b & 1) r = r * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return r;
}
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
int main() {
  long long i, j, k, n, m, l, s = 0, x, y, tc = 1, p, q, a, b, c = 0;
  bool f = 0, ff = 0;
  string st;
  char ch;
  while (cin >> st) {
    vector<long long> qq, aa;
    for (i = 0; i < st.size(); i++) {
      if (st[i] == 'Q') {
        qq.push_back(i + 1);
      }
      if (st[i] == 'A') {
        aa.push_back(i + 1);
      }
    }
    c = 0;
    for (i = 0; i < qq.size(); i++) {
      x = qq[i];
      for (j = 0; j < aa.size(); j++) {
        if (aa[j] < x) continue;
        y = aa[j];
        if (upper_bound(qq.begin(), qq.end(), y) == qq.end()) break;
        c += qq.size() - (lower_bound(qq.begin(), qq.end(), y) - qq.begin());
      }
    }
    cout << c << en;
  }
}
