#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T const& Max(T& a, T& b) {
  return a < b ? b : a;
}
template <class T>
inline const void read(T& second) {
  for (auto& i : second) cin >> i;
}
template <class Y>
inline void print(Y second, int size) {
  for (int i = 0; i < size; i++) cerr << second[i] << " ";
}
namespace file {
void subl() {}
void fileio(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
}  // namespace file
void solve() {
  string a;
  cin >> a;
  int N = a.length();
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == 'Q')
      for (int j = i; j < N; j++) {
        if (a[j] == 'A')
          for (int k = j; k < N; k++) {
            if (a[k] == 'Q') ans++;
          }
      }
  }
  cout << ans << endl;
}
int main() {
  file::subl();
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
