#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
string s;
int ans;
int main() {
cin >> s;
int len = s.length();
for (int i = 0;i < len;++i) {
if (s[i] == 'A') {
int a = 0;
int b = 0;
for (int j = i - 1;j >= 0;--j) {
if (s[j] == 'Q') {
a++;
}
}
for (int j = i + 1;j < len;++j) {
if (s[j] == 'Q') {
b++;
}
}
ans += a*b;
}
}
cout << ans << endl;
return 0;
}