#include <bits/stdc++.h>
using namespace std;
int main() {
  string second;
  vector<char> ch{'Q', 'A', 'Q'};
  cin >> second;
  vector<vector<long long> > vec(3);
  for (long long i = 0; i < 3; i++) vec[i].resize(second.length());
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j < second.length(); j++) vec[i][j] = 0;
  for (long long i = 0; i < 3; i++) {
    for (long long j = i; j < second.length(); j++) {
      if (ch[i] == second[j] && j == 0 && i == 0)
        vec[i][j] = 1;
      else if (ch[i] == second[j] && i == 0)
        vec[i][j] = vec[i][j - 1] + 1;
      else if (ch[i] == second[j])
        vec[i][j] = vec[i][j - 1] + vec[i - 1][j];
      else if (j != 0)
        vec[i][j] = vec[i][j - 1];
    }
  }
  cout << vec[2][second.length() - 1];
  return 0;
}
