"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 java.io.*;
import java.util.*;

public class cftest implements Runnable {

    private static final int MAX = (int) (1E5 + 5);
    private static final int MOD = (int) (1E9 + 7);
    private static final long Inf = (long) (1E14 + 10);
    static ArrayList<Integer> [] adj;
    boolean flag=false;
    static int[][] dp;
    
    private void solve() throws IOException {
        //int t = reader.nextInt();
        int t=1;
        while(t--!=0){
            String s = reader.next();
            StringBuilder sb = new StringBuilder();
            for (int i = s.length() - 1; i >= 0; i--) {
               if(s.charAt(i)=='A'||s.charAt(i)=='Q') sb.append(s.charAt(i)) ;
            }
            s=sb.toString();
            if(s.isEmpty()){
                System.out.println(0);
                return;
            }
           // System.out.println(s);
            int n = s.length();
            int[] dpq = new int[n];
            int[] dpaq = new int[n];
            if(s.charAt(0)=='Q'){
                dpq[0]=1;
            }
            int ans=0;
            for (int i = 1; i < n; i++) {
                if(s.charAt(i)=='Q'){
                    if(dpaq[i-1]>0){
                        ans+=dpaq[i-1];
                    }
                    dpq[i]=1+dpq[i-1];
                    dpaq[i]=dpaq[i-1];
                }else if(s.charAt(i)=='A'){
                    dpq[i]=dpq[i-1];
                    dpaq[i]+=(dpq[i-1]+dpaq[i-1]);
                }
            }
            System.out.println(ans);



        }

    }
    public static void display(int[] arr){
        System.out.println("---------------------");
        //System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }






   
   
   
    //+++++++++++++++++++++++++++++++++++++TEMPLATE++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new cftest().run();
        }
    }
    StandardInput reader;
    PrintWriter writer;
    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

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

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

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}