#include <bits/stdc++.h>
const int numTests = 2;
using namespace std;
template <typename T>
void debug(const T &value) {}
template <typename C>
void debug(const vector<C> &arr) {}
template <typename T, typename... Args>
void debug(const T &value, Args... args) {}
template <typename T>
T bin_pow_mod(T x, int p, T m) {
  x %= m;
  T result = 1;
  while (p > 0) {
    if (p % 2 == 1) {
      result = (result * x) % m;
      p--;
    } else {
      x = (x * x) % m;
      p /= 2;
    }
  }
  return result;
}
class Solver {
 private:
  istream &in;
  ostream &out;
  string s;

 public:
  Solver(istream &in, ostream &out) : in(in), out(out) {}
  void readInput() { in >> s; }
  void solve() {
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
      for (int j = i + 1; j < s.size(); j++) {
        for (int k = j + 1; k < s.size(); k++) {
          if (s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q') {
            debug("i = ", i, "; j = ", j, "; k = ", k, "; ",
                  vector<int>{1, 2, 3, 4});
            cnt++;
          }
        }
      }
    }
    out << cnt << endl;
  }
};
bool test(const string &expected, const string &result, const string &message) {
  if (expected != result) {
    cerr << "Assertion failed: " << message << endl;
    cerr << "Expected: " << expected << endl;
    cerr << "Result: " << result << endl;
    return false;
  }
  return true;
}
int main() {
  Solver solver(cin, cout);
  solver.readInput();
  solver.solve();
  return 0;
}
