"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".
'''input
1 2 3
4 5
6 7 8
45 9
'''

import sys
pow2 = pow              # for modular expo pow2(base, n, mod)
from math import *
from time import time
from collections import defaultdict
from bisect import bisect_right, bisect_left
from string import ascii_lowercase as lcs
from string import ascii_uppercase as ucs
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
#getcontext().prec = 500
#sys.setrecursionlimit(30000)

# What doesn't challenge you, makes you weaker.

mod = 10**9 + 7
INF = sys.maxint

raw_input = lambda: sys.stdin.readline().rstrip()
die = lambda : exit(0)
flush= lambda : sys.stdout.flush()

r_s = lambda: raw_input().strip()                   #read str
r_ss = lambda: raw_input().split()          #read stringss
r_i = lambda: int(raw_input())              #read int
r_is = lambda: map(int, raw_input().split())#read ints
r_f = lambda: float(raw_input())            #read float
r_fs = lambda: map(Decimal, raw_input().split()) #read floats

# For effieciently taking lots of queries with each query in a separate line
# having integer values separated by space. A 2d list is made with each row
# corresponding to line. Each row is a list with all the values.
# Use this for fast I/O by taking all input in one go.
r_qs = lambda: map(lambda s:map(int, s.split(' ')), sys.stdin.readlines())

'''-------------------------------------------------------------------'''

# Call it as dbg(varName=varName)
def dbg(**kwargs):
    print "Value of '" + kwargs.keys()[0] + "' is", kwargs[kwargs.keys()[0]]


def main():
    s = r_s()
    ans = 0
    n = len(s)
    for i in range(n):
        if s[i]!='Q':
            continue
        for j in range(i+1,n):
            if s[j]!='A':
                continue
            for k in range(j+1, n):
                if s[k]!='Q':
                    continue
                ans+=1
    print ans

if __name__ == '__main__':
    local = True
    # local = False
    if local:
        try:
            sys.stdin = open('input.txt')
            print 'Running at local.'
            for i in range(r_i()):
                main()
        except IOError:
            main()
    else:
        main()


