Educational Codeforces Round 56 (Rated for Div. 2)

A. Dice Rolling

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mishka got a six-faced dice. It has integer numbers from 22 to 77 written on its faces (all numbers on faces are different, so this is an almostusual dice).

Mishka wants to get exactly xx points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.

Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly xxpoints for them. Mishka is very lucky, so if the probability to get xx points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.

Mishka is also very curious about different number of points to score so you have to answer tt independent queries.

Input

The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of queries.

Each of the next tt lines contains one integer each. The ii-th line contains one integer xixi (2≤xi≤1002≤xi≤100) — the number of points Mishka wants to get.

Output

Print tt lines. In the ii-th line print the answer to the ii-th query (i.e. any number of rolls Mishka can make to be able to get exactly xixi points for them). It is guaranteed that at least one answer exists.

Example

input

4
2
13
37
100

output

1
3
8
27

Note

In the first query Mishka can roll a dice once and get 22 points.

In the second query Mishka can roll a dice 33 times and get points 55, 55 and 33 (for example).

In the third query Mishka can roll a dice 88 times and get 55 points 77 times and 22 points with the remaining roll.

In the fourth query Mishka can roll a dice 2727 times and get 22 points 1111 times, 33 points 66 times and 66 points 1010 times.

 

#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	scanf("%d",&T);
	int x;
	while(T--){
		scanf("%d",&x);
		
		printf("%d\n",x/2);
	}
} 

 

B. Letters Rearranging

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a string ss consisting only of lowercase Latin letters.

You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.

Let's call a string good if it is not a palindrome. Palindrome is a string which is read from left to right the same as from right to left. For example, strings "abacaba", "aa" and "z" are palindromes and strings "bba", "xd" are not.

You have to answer tt independent queries.

Input

The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — number of queries.

Each of the next tt lines contains one string. The ii-th line contains a string sisi consisting only of lowercase Latin letter. It is guaranteed that the length of sisi is from 11 to 10001000 (inclusive).

Output

Print tt lines. In the ii-th line print the answer to the ii-th query: -1 if it is impossible to obtain a good string by rearranging the letters of sisiand any good string which can be obtained from the given one (by rearranging the letters) otherwise.

Example

input

3
aa
abacaba
xdd

output

-1
abaacba
xdd

Note

In the first query we cannot rearrange letters to obtain a good string.

Other examples (not all) of correct answers to the second query: "ababaca", "abcabaa", "baacaba".

In the third query we can do nothing to obtain a good string.

#include<bits/stdc++.h>
using namespace std;
char s[1005];
int main(){
	int T;
	scanf("%d",&T);
	getchar();
	while(T--){
		scanf("%s",s);
		int l=strlen(s);
		sort(s,s+l);
		if(s[0]==s[l-1])
		printf("-1\n");
		else printf("%s\n",s); 
	}
}

C. Mishka and the Last Exam

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left.

There were nn classes of that subject during the semester and on ii-th class professor mentioned some non-negative integer aiai to the students. It turned out, the exam was to tell the whole sequence back to the professor.

Sounds easy enough for those who attended every class, doesn't it?

Obviously Mishka didn't attend any classes. However, professor left some clues on the values of aa to help out students like Mishka:

  • aa was sorted in non-decreasing order (a1≤a2≤⋯≤ana1≤a2≤⋯≤an);
  • nn was even;
  • the following sequence bb, consisting of n2n2 elements, was formed and given out to students: bi=ai+an−i+1bi=ai+an−i+1.

Professor also mentioned that any sequence aa, which produces sequence bb with the presented technique, will be acceptable.

Help Mishka to pass that last exam. Restore any sorted sequence aa of non-negative integers, which produces sequence bb with the presented technique. It is guaranteed that there exists at least one correct sequence aa, which produces the given sequence bb.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of sequence aa. nn is always even.

The second line contains n2n2 integers b1,b2,…,bn2b1,b2,…,bn2 (0≤bi≤10180≤bi≤1018) — sequence bb, where bi=ai+an−i+1bi=ai+an−i+1.

It is guaranteed that there exists at least one correct sequence aa, which produces the given sequence bb.

Output

Print nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10180≤ai≤1018) in a single line.

a1≤a2≤⋯≤ana1≤a2≤⋯≤an should be satisfied.

bi=ai+an−i+1bi=ai+an−i+1 should be satisfied for all valid ii.

Examples

input

4
5 6

output

2 3 3 3

input

6
2 1 2

output

0 0 1 1 1 2 
#include<bits/stdc++.h>
using namespace std;
long long a[200005];
int main(){
	int n;
	scanf("%d",&n);
	long long b;
	for(int i=1;i*2<=n;i++){
		scanf("%lld",&b);
		if(i==1)
		a[i]=0;
		else a[i]=max(a[i-1],b-a[n-i+2]);
		a[n-i+1]=b-a[i];
	}
	printf("%lld",a[0]);
	for(int i=2;i<=n;i++){
		printf(" %lld",a[i]);
	}
}

D. Beautiful Graph

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an undirected unweighted graph consisting of nn vertices and mm edges.

You have to write a number on each vertex of the graph. Each number should be 11, 22 or 33. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd.

Calculate the number of possible ways to write numbers 11, 22 and 33 on vertices so the graph becomes beautiful. Since this number may be large, print it modulo 998244353998244353.

Note that you have to write exactly one number on each vertex.

The graph does not have any self-loops or multiple edges.

Input

The first line contains one integer tt (1≤t≤3⋅1051≤t≤3⋅105) — the number of tests in the input.

The first line of each test contains two integers nn and mm (1≤n≤3⋅105,0≤m≤3⋅1051≤n≤3⋅105,0≤m≤3⋅105) — the number of vertices and the number of edges, respectively. Next mm lines describe edges: ii-th line contains two integers uiui, vivi (1≤ui,vi≤n;ui≠vi1≤ui,vi≤n;ui≠vi) — indices of vertices connected by ii-th edge.

It is guaranteed that ∑i=1tn≤3⋅105∑i=1tn≤3⋅105 and ∑i=1tm≤3⋅105∑i=1tm≤3⋅105.

Output

For each test print one line, containing one integer — the number of possible ways to write numbers 11, 22, 33 on the vertices of given graph so it becomes beautiful. Since answers may be large, print them modulo 998244353998244353.

Example

input

2
2 1
1 2
4 6
1 2
1 3
1 4
2 3
2 4
3 4

output

4
0

Note

Possible ways to distribute numbers in the first test:

  1. the vertex 11 should contain 11, and 22 should contain 22;
  2. the vertex 11 should contain 33, and 22 should contain 22;
  3. the vertex 11 should contain 22, and 22 should contain 11;
  4. the vertex 11 should contain 22, and 22 should contain 33.

In the second test there is no way to distribute numbers.

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=998244353;
int n,m,u,v,c[maxn],r[2],s;
int p[maxn]={1};
vector<int>g[maxn];
int dfs(int u,int x){
	if(c[u])return c[u]==x;
 	c[u]=x;
 	r[x&1]++;
 	for(int v:g[u]) {
  	if(!dfs(v,x^1))
   	return false;
 	}
 	return true;
}
int main(){
	int T;
	for(int i=1;i<maxn;i++)
	p[i]=p[i-1]*2%mod;
	scanf("%d",&T);
	while(T--){
		s=1;
		scanf("%d%d",&n,&m);
		while(m--){
			scanf("%d%d",&u,&v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for(int i=1;i<=n;i++){
			if(!c[i]){
				r[0]=r[1]=0;
				if(!dfs(i,2)){
					s=0;
					break;
				}
				s=(long long)s*(p[r[0]]+p[r[1]])%mod;
			}
		}
		printf("%d\n",s);
  		for(int i=1;i<=n;i++){g[i].clear();c[i]=0;}
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值