#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long dem = 0;
  vector<long long> a, b, c;
  for (long long i = 0; i < s.size(); i++)
    if (s[i] == 'Q')
      a.push_back(++dem);
    else
      a.push_back(dem);
  dem = 0;
  for (long long i = 0; i < s.size(); i++)
    if (s[i] == 'A' && i != 0)
      b.push_back(dem += a[i - 1]);
    else
      b.push_back(dem);
  dem = 0;
  for (long long i = 0; i < s.size(); i++)
    if (s[i] == 'Q' && i != 0)
      c.push_back(dem += b[i - 1]);
    else
      c.push_back(dem);
  cout << c[c.size() - 1];
}
