"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

  1. QAQAQYSYIOIWIN

Output

  1. 4

Input

  1. QAQQQZZYNOIWIN

Output

  1. 3

Note

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

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

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstring>
  5. using namespace std;
  6. int main()
  7. {
  8. string str;
  9. cin>>str;
  10. int s2,s1,s=0;
  11. for(int t=0;t<str.length();t++)
  12. {
  13. if(str[t]=='A')
  14. {
  15. s1=0;
  16. s2=0;
  17. for(int j=0;j<t;j++)
  18. {
  19. if(str[j]=='Q')
  20. s1++;
  21. }
  22. for(int j=t+1;j<str.length();j++)
  23. {
  24. if(str[j]=='Q')
  25. s2++;
  26. }
  27. s+=s1*s2;
  28. }
  29. }
  30. cout<<s<<endl;
  31. return 0;
  32. }

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. 延时加载 lazyload使用技巧

    html <img class="lazy" src="images/src_unit.png" data-src="images/index/ ...

  2. 第一节 课程简介与HTML5概述

    第一节 课程简介与HTML5概述 *********************************************************** 1.1课程简介 教学目的: 从基础入手到能够运 ...

  3. Wireshark 的使用 —— 过滤器(filter)

    1. 基本 ip 地址: 目的IP:ip.dst==192.168.101.8,源ip:ip.src==1.1.1.1 不区分源和目的:ip.addr == 192.168.101.8: 端口过滤: ...

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

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

  5. 选中DataGrid的Cell而不是row

    主要是针对DataGridCellsPresenter而不是SelectiveScrollingGrid,使用时DataGridRow应用这个style就可以了. <Style x:Key=&q ...

  6. C#支持从自定义日期时间格式到DateTime类型

            /// <summary>         ///         /// </summary>         /// <param name=&quo ...

  7. webAPP meta 标签大全

    1.先说说mate标签里的viewport: viewport即可视区域,对于桌面浏览器而言,viewport指的就是除去所有工具栏.状态栏.滚动条等等之后用于看网页的区域.对于传统WEB页面来说,9 ...

  8. Linux 包管理基础:apt、yum、dnf 和 dpkg

    https://linux.cn/article-8782-1.html 1. apt-get 安装( 在线) 会帮我把所有的依赖包都一起安装 apt-get install xxx 安装xxx .如 ...

  9. [hdu2087]剪花布条(KMP)

    题意:求存在模式串个数,不可重复. 解题关键:模板题.整理模板用.重复和不可重复的区别在下面已标出.主要是j的变化. #include<cstdio> #include<cstrin ...

  10. Permutacja

    题意: 要求动态求问是否有一个 1~n 的排列,使得满足 $p_i \leq a_i$,给定 $a_i$ 初始值,接下来 m次单个位置修改,每次求问是否可以构造出来. 解法: 构造一序列使得 $cnt ...