A. QAQ【题目链接】

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

"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

Copy

QAQAQYSYIOIWIN

output

Copy

4

input

Copy

QAQQQZZYNOIWIN

output

Copy

3

Note

In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".

将每个'A'两边的'Q'个数相乘之后加和即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;int main()
{ll n;string s;ll i;cin>>s;ll q=0;ll l=s.length();for(i=0;i<l;i++){if(s[i]=='Q') q++;}ll ans=0;ll temp=0;for(i=0;i<l;i++){if(s[i]=='Q')temp++;if(s[i]=='A'){ans+=temp*(q-temp);}}cout<<ans<<endl;return 0;
}

【codeforces 894A】QAQ相关推荐

  1. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  2. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  3. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

  4. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

  5. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

  6. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  7. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  8. 【codeforces 711B】Chris and Magic Square

    [题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...

  9. 【codeforces 807C】Success Rate

    [题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...

  10. 【codeforces 766E】Mahmoud and a xor trip

    [题目链接]:http://codeforces.com/contest/766/problem/E [题意] 定义树上任意两点之间的距离为这条简单路径上经过的点; 那些点上的权值的所有异或; 求任意 ...

最新文章

  1. MPlayer编译步骤
  2. OpenStack Austin 峰会观察:OpenStack as IaaS 已是过去,Solutions on OpenStack 才是未来
  3. 矩阵从左上到右下的最短距离问题
  4. K8S部署工具:KubeOperator集群规划-手动模式
  5. 如何将现有的项目添加到远程的git库里面!
  6. [APIO2014] 序列分割(斜率优化dp)
  7. ubuntu下sogou突然不能用
  8. MySql数据库连接种类
  9. 计算机网络课程设计之Tracert与Ping程序设计与实现
  10. Golang Post传参调用示例
  11. 8 定制10MINs 3
  12. php pdo-insert,php mysql pdo insert multiple rows 批量插入
  13. HTTP协议和HttpClient的入门
  14. CSDN博客 不登录不能复制粘贴
  15. doc 问卷调查模板表_调查问卷模板.doc
  16. 计算机键盘无法使用怎么处理,为什么键盘不能用 键盘不能用怎么办
  17. 服务器安装docker和docker-compose,并开放2375端口
  18. 霍华德:二呆青年勤修苦练终成一代大侠记
  19. Python网络爬虫及数据可视化(软科中国大学专业排名|计算机科学与技术)
  20. 【MyBatis框架】核心配置文件讲解

热门文章

  1. Uniapp实现加入购物车抛物线效果
  2. 安装VMware出现无效驱动器
  3. 鲁大师Q3季度电动车报告:最聪明的电动车跑分曝光
  4. Unity Input键盘输入无反应
  5. 【TK精灵】一款界面友好的桌面程序(exe)进程守护管理软件
  6. theos tweak导入自定义类
  7. Linux命令行设置行数,Linux设置history命令显示行数以及时间
  8. 制造业执行系统MES 在汽车零配件行业展露锋芒
  9. 最优阵列处理技术/Harry L. Van Trees——学习笔记2
  10. mybatis获取map中的key和value