"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.

Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!).

<image> illustration by 猫屋 https://twitter.com/nekoyaliu

Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.

Input

The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.

Output

Print a single integer — the number of subsequences "QAQ" in the string.

Examples

Input

QAQAQYSYIOIWIN


Output

4


Input

QAQQQZZYNOIWIN


Output

3

Note

In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".


import sun.font.FontRunIterator;

import java.io.*;
import java.util.*;

public class Main {

    private static BufferedReader br;
    private static StringTokenizer st;
    private static PrintWriter out;

    public static int checker(int i){
        int ans = 0;
        while (i > 0){
            ans += i%10;
            i/=10;
        }
        return ans;
    }
    public static void main(String[] args) throws IOException {
        smart_init("rec.in", "rec.out");
        String s[] = next().split("");
        long pref[] = new long[s.length];
        long y = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i].equals("Q"))y++;
            pref[i] = y;
        }
        long ans = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i].equals("A")){
                long sleva = 0;
                long sprava = 0;
                if (i > 0)sprava = pref[i - 1];
                if (i < s.length - 1) sleva = pref[s.length-1] - pref[i];
                ans += sleva * sprava;
            }
        }
        out.println(ans);
        out.close();
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static String next() throws IOException {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    private static void smart_init(String s, String s1) throws IOException{
        try {
            file_init(s , s1);
        }catch (Exception e){
            io_init();
        }
    }
    private static void io_init() throws IOException{
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }
    private static void file_init(String s, String s1) throws IOException{
        br = new BufferedReader(new FileReader(s));
        out = new PrintWriter(s1);
    }
}
class Zapros implements Comparator<Zapros>{
    int zap, poz;
    public Zapros(){
    }
    public Zapros(int zap, int poz){
        this.zap = zap;
        this.poz = poz;
    }
    @Override
    public int compare(Zapros o1 , Zapros o2){
        return Integer.compare(o1.zap , o2.zap);
    }
}