"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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author warez80
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		char[] S;
		long[][] memo;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			S = in.next().toCharArray();
			memo = new long[3][S.length];
			for (long[] x : memo) Arrays.fill(x, -1);
			out.println(go(0, 0));
		}

		long go(int phase, int idx) {
			if (phase == 3) return 1;
			if (idx == S.length) return 0;
			if (memo[phase][idx] != -1) return memo[phase][idx];
			long ans = go(phase, idx + 1);
			switch (phase) {
				case 0:
				case 2:
					if (S[idx] == 'Q') ans += go(phase + 1, idx + 1);
					break;
				case 1:
					if (S[idx] == 'A') ans += go(phase + 1, idx + 1);
			}
			return memo[phase][idx] = ans;
		}

	}

	static class FastScanner {
		private byte[] buffer = new byte[1 << 10];
		private int bp;
		private int br;
		private InputStream is;
		private boolean empty;
		private boolean skipLF;

		public FastScanner(InputStream in) {
			is = in;
		}

		private byte r() {
			if (empty) throw new UnknownError();
			if (bp == br) try {
				br = is.read(buffer, bp = 0, 1 << 10);
				if (br == -1) buffer[0] = -1;
			} catch (Exception e) {
			}
			if (bp >= buffer.length || buffer[bp] == -1) {
				empty = true;
				return -1;
			}
			return buffer[bp++];
		}

		private byte rnw() {
			skipLF = false;
			byte c;
			do c = r(); while (c <= ' ');
			return c;
		}

		private static byte[] expand(byte[] b) {
			byte[] newa = new byte[b.length << 1];
			System.arraycopy(b, 0, newa, 0, b.length);
			return newa;
		}

		public String next() {
			byte c = rnw(), buf[] = new byte[64];
			int cnt = 0;
			do {
				if (c <= ' ') break;
				if (cnt == buf.length) buf = expand(buf);
				buf[cnt++] = c;
			} while ((c = r()) != -1);
			return new String(buf, 0, cnt);
		}

	}
}

