#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
string s;
unsigned long long dp[100][4];
bool vis[100][4];
unsigned long long f(int x, int y) {
  if (x >= s.size()) return y == 3;
  if (vis[x][y]) return dp[x][y];
  unsigned long long ret = f(x + 1, y);
  if (y == 0 && s[x] == 'Q') {
    ret = ret + f(x + 1, y + 1);
  }
  if (y == 1 && s[x] == 'A') {
    ret = ret + f(x + 1, y + 1);
  }
  if (y == 2 && s[x] == 'Q') {
    ret = ret + f(x + 1, y + 1);
  }
  vis[x][y] = 1;
  return dp[x][y] = ret;
}
void init() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  cin >> s;
  memset((vis), 0, sizeof(vis));
  unsigned long long ans = f(0, 0);
  cout << ans << "\n";
  return 0;
}
