Yesterday participated in a practice session of nowcoder,Then I met a question similar to the previous one.

### nowcoder-847-A QAQ

Descrption:

1≤x,y,z≤N
x<y−1
y<z−1
Sx='Q',Sy='A',Sz='Q'

N不会在输入中给出。

S中只包含大写字母。

QQAQQ

1

<1,3,5>

QAQAQ

0

QQHAHAQQAQ

10

Intentional analysis:

QAQ,let's look it carefully.Then we can find that the amount of "QAQ" is depends on the amount of "A".So our task is find the position of "A".
Attention: You can't choose neighboring char from the original string.

Click to see Chinese Intentional analysis 观察一下可以发现，QAQ的数量取决于A的数量。所以我们只需要找到A的数量，然后进行判断计算就行。 注意：这道题要求的QAQ不能是在原字符串中相邻的字符。

For example:

QAQAQ
12345

We can find "QAQ" at:
1 2 3
1 2 5
1 4 5
3 4 5

but all of these have neighboring char,so the answer of this example is "0",not "4".


Code:

#include<bits/stdc++.h>
using namespace std;
string s;
long long ans;
int main()
{
cin>>s;
int l=s.size();
for(int i=0;i<l;i++)
{
if(s[i]=='A')
{
int a=0;
int b=0;
for(int j=i-2;j>=0;j--)
{
if(s[j]=='Q')
a++;
}
for(int k=i+2;k<l;k++)
{
if(s[k]=='Q')
b++;
}
ans+=a*b;
}
}
cout<<ans<<endl;
return 0;
}


One more thing you should better focus on:
The answer is too big to be able to save a int type.I ffailed once because of this.

### A similar question:

CodeForces-894-A QAQ

Descripition:
"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!).

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".

This is similar to the previois.The only thing different is choose a neighboring char is allowed here.So we just correct a number then we can solve this problem.

Code:

#include<bits/stdc++.h>
using namespace std;
string s;
long long ans;
int main()
{
cin>>s;
int l=s.size();
for(int i=0;i<l;i++)
{
if(s[i]=='A')
{
int a=0;
int b=0;
for(int j=i-2;j>=0;j--)
{
if(s[j]=='Q')
a++;
}
for(int k=i+2;k<l;k++)
{
if(s[k]=='Q')
b++;
}
ans+=a*b;
}
}
cout<<ans<<endl;
return 0;
}


You can find the difference between these two codes which is better for you to understand this series of questions.

### The most exciting thing I want to say is

1. 我中奖啦
2. I got the prize
3. Gané el premio.
4. Ek het die prys gewen.
5. Kam fituar çmimin.
6. ሽልማቱን አሸንፌያለሁ.
7. Ես հաղթել եմ մրցանակին:
8. Mükafatı qazandım.
9. Saria irabazi nuen.
10. Я выйграў латарэю сяброў
......

After nearly half a year of competition on the nowcoder.Participated in 18 games,I won the price at last.Congratulations!

Show off