"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".
/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    static void shuffle( int arr[], int n)
    {
        // Creating a object for Random class
        Random r = new Random();
         
        // Start from the last element and swap one by one. We don't
        // need to run for the first element that's why i > 0
        for (int i = n-1; i > 0; i--) {
             
            // Pick a random index from 0 to i
            int j = r.nextInt(i+1);
             
            // Swap arr[i] with the element at random index
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        // Prints the random array
       // System.out.println(Arrays.toString(arr));
    }
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        int[][] tdiarr(int m , int n){
            int[][] a = new int[m][n];
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    a[i][j]=Integer.parseInt(next());
                }
            }
            return a;
        } 
        int[] niarr(int n)
        {
            int[] a = new int[n];
            for(int i=0;i<n;i++)a[i]=Integer.parseInt(next());
            return a;
        }
        long[] nlarr(int n)
        {
            long[] a = new long[n];
            for(int i=0;i<n;i++)a[i]=Long.parseLong(next());
            return a;
        }
        char[] ncarr(){
            return next().trim().toCharArray();
            
            
        }
        
  
        int ni() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nl() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nd() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nstr() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
    static FastReader br=new FastReader();//(new InputStreamReader(System.in));
		
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int t=1;
		br=new FastReader();
	///	t=br.ni();//Integer.parseInt(br.readLine().trim());
		StringBuilder sb=new StringBuilder();
	in1 :	while(t-->0)
		{
		    sb.append(solve());
		}
			//			System.out.println("OUTPUT:::");
	
		System.out.println(sb);
	}
	static int solve(){
	    char[] a = br.ncarr();
	    int n = a.length;
	    int[] dp1 = new int[n];
	    for(int i=0;i<n;i++){
	        if(i==0){
	            if(a[i]=='Q')dp1[0]=1;
	        }
	        else {
	            if(a[i]=='Q')dp1[i]=1+dp1[i-1];
	            else dp1[i]=dp1[i-1];   
	        }
	    }
	    int[] dp2 = new int[n];
	    for(int i=0;i<n;i++){
	        if(i==0){
	            if(a[n-1-i]=='Q')dp2[n-1-i]=1;
	        }
	        else {
	            if(a[n-1-i]=='Q')dp2[n-1-i]=1+dp2[n-i-1+1];
	            else dp2[n-1-i]=dp2[n-1-i+1];   
	        }
	    }
	    int ans = 0;
	    for(int i=0;i<n;i++){
	        if(a[i]=='A'){
	            ans += (dp1[i] * dp2[i]);
	        }
	    }
	    return ans;
	    
	    
	  //  return 0;
	    
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}


