#include <bits/stdc++.h>
using namespace std;
long long poww(long long a, long long b) {
  long long ans = 1, base = a;
  while (b != 0) {
    if (b & 1) {
      ans = ans * base;
    }
    base = base * base;
    b >>= 1;
  }
  return ans;
}
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int out = 0, fh = 1;
  char cc = getchar();
  if (cc == '-') fh = -1;
  while (cc > '9' || cc < '0') cc = getchar();
  while (cc >= '0' && cc <= '9') {
    out = out * 10 + cc - '0';
    cc = getchar();
  }
  return out * fh;
}
inline void write(int x) {
  if (x == 0) {
    putchar('0');
    putchar('\n');
    return;
  }
  if (x < 0) {
    putchar('-');
    x *= -1;
  }
  int num = 0;
  char c[15];
  while (x) c[++num] = (x % 10) + 48, x /= 10;
  while (num) putchar(c[num--]);
  putchar('\n');
}
long long poww(long long a, long long b, long long mod) {
  long long ans = 1, base = a;
  while (b != 0) {
    if (b & 1) {
      ans = ans * base % mod;
    }
    base = base * base % mod;
    b >>= 1;
  }
  return ans % mod;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long r = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return r;
}
int abs(int a) {
  if (a >= 0)
    return a;
  else
    return -a;
}
int main() {
  int a = 0, b = 0, cntt = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'A') {
      for (int j = 0; j < i; j++) {
        if (s[j] == 'Q') a++;
      }
      for (int j = i + 1; j < s.length(); j++) {
        if (s[j] == 'Q') b++;
      }
      cntt += a * b;
      a = 0, b = 0;
    } else
      continue;
  }
  cout << cntt << endl;
  return 0;
}
