#include <bits/stdc++.h>
using namespace std;
int val{0};
struct Triplet {
  char letter;
  int onePosn;
  int otherPosn;
};
int findContinuous(string s) {
  int j{0};
  for (auto i = 0; i < s.length() - 2; i++) {
    if (s[i] == 'Q' && s[i + 1] == 'A' && s[i + 2] == 'Q') {
      j++;
    }
  }
  return j;
}
int findLastQ(string s) {
  int j{0};
  for (auto i = 0; i < s.length() - 1; i++) {
    if (s[i] == 'Q' && s[i + 1] == 'A') {
      for (int k = i + 2; k < s.length(); k++) {
        if (s[k] == 'Q') {
          j++;
        }
      }
    }
  }
  return j;
}
int findFirstQ(string s) {
  int j{0};
  for (auto i = 0; i < s.length() - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'Q') {
      for (int k = 0; k < i; k++) {
        if (s[k] == 'Q') {
          j++;
        }
      }
    }
  }
  return j;
}
int findDisjoint(string s) {
  int j{0};
  for (auto i = 0; i < s.length(); i++) {
    int before{0};
    int after{0};
    if (s[i] == 'A') {
      for (int k = 0; k < i; k++) {
        if (s[k] == 'Q') {
          before++;
        }
      }
      for (int k = i + 1; k < s.length(); k++) {
        if (s[k] == 'Q') {
          after++;
        }
      }
      j += before * after;
    }
  }
  return j;
}
int main() {
  string s;
  cin >> s;
  int n = findDisjoint(s);
  cout << n;
  return 0;
}
