"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 PRACTICE;
	import java.util.Scanner.*;
	import java.io.BufferedReader;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.InputStreamReader;
	import java.io.InputStreamReader;
	import java.util.*;
	
	
	public class Q1 {
	    static Reader r1;
	    
	    public Q1() {
	        r1 = new Reader();
	        Reader.init(System.in);
	    }
	  
	    public static void main(String[] args) throws IOException {
	        Q1 lc = new Q1();
	        
	        String s = r1.next();
	        
	        int[] Q = new int[s.length()];
	        int[] Q2 = new int[s.length()];
	        int[] A = new int[s.length()];
	        int[] QA = new int[s.length()];
	        int[] QAQ = new int[s.length()];
	        
	        for(int i=0;i<s.length();i++) {
	        	if(s.charAt(i)=='Q') {
	        		Q[i]=1;
	        		Q2[i]=1;
	        	}
	        }
	        
	        for(int i=0;i<s.length();i++) {
	        	if(s.charAt(i)=='A') {
	        		A[i]=1;
	        	}
	        }
	        
	        int current=0;
	        for(int i=0;i<Q.length;i++) {
	        	if(Q[i]==1) {
	        		current++;
	        	}
	        	Q[i]=current;
	        }
	        
	        
	        for(int i=0;i<A.length;i++) {
	        	if(A[i]==1) {
	        		QA[i]=Q[i];
	        	}
	        }
	        
	        
	        
	        
	        current=0;
	        for(int i=0;i<QA.length;i++) {
	        	if(QA[i]!=0) {
	        		current+=QA[i];
	        	}
	        	QA[i]=current;
	        }
	        
	        
//	        for(int i=0;i<A.length;i++) {
//	        	System.out.print(QA[i]+" ");
//	        }
	        
	        
	        int sum=0;
	        for(int i=0;i<QAQ.length;i++) {
	        	if(Q2[i]!=0) {
	        		QAQ[i]=QA[i];
	        		sum+=QAQ[i];
	        	}
	        }
	        
	        
	        
	        
	        System.out.println(sum);
	        
	        
	       
	        
	        
	        
	        
	        
	        
	        
	        
	        
	        
	        
	        
	        
	    }
	    
	 
	  
	}
	
	
	
	
	
	        
	        
	        
	        
	        
	        
	        
	        
	        
	        
	
	
	
	
	
	
	
	
	
	/** Class for buffered reading long and double values */
	class Reader {
	    static BufferedReader reader;
	    static StringTokenizer tokenizer;
	
	    /** call this method to initialize reader for InputStream */
	    static void init(InputStream input) {
	        reader = new BufferedReader(
	                     new InputStreamReader(input) );
	        tokenizer = new StringTokenizer("");
	    }
	
	    /** get next word */
	    static String next() throws IOException {
	        while ( ! tokenizer.hasMoreTokens() ) {
	            //TODO add check for eof if necessary
	            tokenizer = new StringTokenizer(
	                   reader.readLine() );
	        }
	        return tokenizer.nextToken();
	    }
	    
	    int nextInt() throws IOException {
	        return Integer.parseInt( next() );
	    }
	
	    long nextlong() throws IOException {
	        return Long.parseLong( next() );
	    }
	    
	    static double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
// 