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

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

题解:去求字符串里面有多少个QAQ字串,可以不连续

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std; int main()
{ string str;
cin>>str;
int s2,s1,s=0;
for(int t=0;t<str.length();t++)
{ if(str[t]=='A')
{
s1=0;
s2=0;
for(int j=0;j<t;j++)
{
if(str[j]=='Q')
s1++;
}
for(int j=t+1;j<str.length();j++)
{
if(str[j]=='Q')
s2++;
}
s+=s1*s2;
}
}
cout<<s<<endl; return 0;
}

CodeForces - 894A-QAQ(思维)的更多相关文章

  1. codeforces #447 894A QAQ 894B Ralph And His Magic Field 894C Marco and GCD Sequence

    A.QAQ 题目大意:从给定的字符串中找出QAQ的个数,三个字母的位置可以不连续 思路:暴力求解,先找到A的位置,往前扫,往后扫寻找Q的个数q1,q2,然 后相乘得到q1*q2,这就是这个A能够找到的 ...

  2. 894A. QAQ#(暴力)

    题目出处:http://codeforces.com/problemset/problem/894/A 题目大意:计数依次出现QAQ的次数 #include<iostream> using ...

  3. CodeForces 604C 【思维水题】`

    题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...

  4. Minimum Integer CodeForces - 1101A (思维+公式)

    You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...

  5. Codeforces 1038D - Slime - [思维题][DP]

    题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...

  6. AND Graph CodeForces - 987F(思维二进制dfs)

    题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一 ...

  7. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  8. Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)

    Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...

  9. Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

    Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...

随机推荐

  1. python学习笔记:第五天( 字典)

    Python3 字典 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格 ...

  2. codeforces 705B B. Spider Man(组合游戏)

    题目链接: B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 【Lintcode】095.Validate Binary Search Tree

    题目: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is define ...

  4. [转]BX9054: 各浏览器对 document.execCommand 方法的首参数可选值范围存在差异

    作者:钱宝坤 标准参考 无. 问题描述 execCommand 方法通常用于控制可编辑的 IFRAME 内容,制作富文本编辑器. 但他现在为止还是非标准的,方法的首参数 Commmands 的可选值由 ...

  5. C#如何立即回收内存

    1.把对象赋值为null 2.立即调用GC.Collect(); 注意:这个也只是强制垃圾回收器去回收,但具体什么时候执行不确定.  代码: class Test { ~Test() { Consol ...

  6. spring-data-cassanra的简单使用

    之前写了JAVA操作cassandra驱动包,现在来看看spring-data对cassandra的支持.这里是spring-data-cassandra的官方文档:http://docs.sprin ...

  7. Windows WMIC命令使用详解1

    https://blog.csdn.net/enweitech/article/details/51982114 在CMD和Powershell中 使用WMIC 先决条件: a. 启动Windows ...

  8. 用c++STL实现进程管理

    项目要求: 设计一个允许n个进程并发运行的进程管理模拟系统.该系统包括有简单的进程控制,其进程调度采用时间片轮转算法.每个进程用一个PCB表示,其内容根据具体情况设置.各进程之间有一定的同步关系(可选 ...

  9. GridSplitter用法

    1.GridSplitter的ShowsPreview设置为True时拖动报null错误 解决方法在Grid外面包装一个装饰器:AdornerDecorator,至于为什么这么做,暂时还不知道 2.当 ...

  10. java&nbsp;Class类

    java Class类 Class类(在java.lang包中,Instances of the class Classrepresent classes and interfaces in a ru ...