Codeforces Round #447 (Div. 2)

                              A. QAQ

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

题解:暴力枚举位置啦

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 char a[105];
 5
 6 int main()
 7 {   scanf("%s",a);
 8     int n=strlen(a),ans=0;
 9     for(int i=0;i<n;i++){
10         if(a[i]!=‘Q‘) continue;
11         for(int j=i+1;j<n;j++){
12             if(a[j]!=‘A‘) continue;
13             for(int k=j+1;k<n;k++) if(a[k]==‘Q‘) ans++;
14         }
15     }
16     cout<<ans<<endl;
17 } 

                              C. Marco and GCD Sequence

In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.

When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be a1,?a2,?...,?an. He remembered that he calculated gcd(ai,?ai?+?1,?...,?aj) for every 1?≤?i?≤?j?≤?n and put it into a set S. gcd here means the greatest common divisor.

Note that even if a number is put into the set S twice or more, it only appears once in the set.

Now Marco gives you the set S and asks you to help him figure out the initial sequence. If there are many solutions, print any of them. It is also possible that there are no sequences that produce the set S, in this case print -1.

Input

The first line contains a single integer m (1?≤?m?≤?1000) — the size of the set S.

The second line contains m integers s1,?s2,?...,?sm (1?≤?si?≤?106) — the elements of the set S. It‘s guaranteed that the elements of the set are given in strictly increasing order, that means s1?<?s2?<?...?<?sm.

Output

If there is no solution, print a single line containing -1.

Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000.

In the second line print n integers a1,?a2,?...,?an (1?≤?ai?≤?106) — the sequence.

We can show that if a solution exists, then there is a solution with n not exceeding 4000 and ai not exceeding 106.

If there are multiple solutions, print any of them.

Examples

Input

42 4 6 12

Output

34 6 12

Input

22 3

Output

-1

Note

In the first example 2?=?gcd(4,?6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai,?ai?+?1,?...,?aj) for every 1?≤?i?≤?j?≤?n.

题解:剽悍的构造题,可惜比赛的时候只想出了一半!

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 const int maxn=1005;
 5
 6 int n;
 7 int a[maxn];
 8
 9 int main()
10 {   cin>>n;
11     int i;
12     for(i=1;i<=n;i++) cin>>a[i];
13     for(i=1;i<=n;i++) if(a[i]%a[1]) break;
14     if(i<=n) puts("-1");
15     else{
16         printf("%d\n%d",2*n-1,a[1]);
17         for(int j=2;j<=n;j++) printf(" %d %d",a[1],a[j]);
18     }
19     return 0;
20 } 
时间: 2024-10-09 01:31:23

Codeforces Round #447 (Div. 2)的相关文章

【Codeforces Round #447 (Div. 2) A】QAQ

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言程序练习题 [代码] #include <bits/stdc++.h> using namespace std; string s; int main(){ #ifdef LOCAL_DEFINE freopen("F:\\c++source\\rush_in.txt", "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0);

Codeforces Round #447 (Div. 2) 题解 【ABCDE】

BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "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 leng

Codeforces Round #447 (Div. 2) C 构造

现在有一个长度为n的数列 n不超过4000 求出它的gcd生成set 生成方式是对<i,j> insert进去(a[i] ^ a[i+1] ... ^a[j]) i<=j 然而现在给你了set 规模m<=1000 求原数列或check不可行 可以想到set中的max数字一定是原数列中的max , min数字一定是所有数字的因子 然而这样就走不下去了,没法通过枚举n或者什么来确定是否存在 一通乱想之后想出来了奇妙的解法.. 解:最小的数字为x 那么原数列中所有的数字都是x的倍数 它们

Codeforces Round #447 (Div. 2) A

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 Dia

Codeforces Round #FF (Div. 2) 题解

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n 

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd