Codeforces Round #527 (Div. 3)

B. Teams Forming

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn students in a university. The number of students is even. The ii-th student has programming skill equal to aiai.

The coach wants to form n2n2 teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).

Students can solve problems to increase their skill. One solved problem increases the skill by one.

The coach wants to know the minimum total number of problems students should solve to form exactly n2n2 teams (i.e. each pair of students should form a team). Your task is to find this number.

Input

The first line of the input contains one integer nn (2≤n≤1002≤n≤100) — the number of students. It is guaranteed that nn is even.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiai is the skill of the ii-th student.

Output

Print one number — the minimum total number of problems students should solve to form exactly n2n2 teams.

Examples

input

6
5 10 2 3 14 5

output

5

input

2
1 100

output

99

Note

In the first example the optimal teams will be: (3,4)(3,4), (1,6)(1,6) and (2,5)(2,5), where numbers in brackets are indices of students. Then, to form the first team the third student should solve 11 problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve 44 problems so the answer is 1+4=51+4=5.

In the second example the first student should solve 9999 problems to form a team with the second one.

#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int a[maxn];
int main(){
	int n,ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	for(int i=1;i<n;i+=2){
		ans+=a[i]-a[i-1];
	} 
	printf("%d\n",ans);
} 

A. Uniform String

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two integers nn and kk.

Your task is to construct such a string ss of length nn that for each ii from 11 to kk there is at least one ii-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minimal frequency of some letter (the frequency of a letter is the number of occurrences of this letter in a string). If there are several possible answers, you can print any.

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.

The next tt lines are contain queries, one per line. The ii-th line contains two integers nini and kiki (1≤ni≤100,1≤ki≤min(ni,26)1≤ni≤100,1≤ki≤min(ni,26)) — the length of the string in the ii-th query and the number of characters in the ii-th query.

Output

Print tt lines. In the ii-th line print the answer to the ii-th query: any string sisi satisfying the conditions in the problem statement with constraints from the ii-th query.

Example

input

3
7 3
4 4
6 2

output

cbcacab
abcd
baabab

Note

In the first example query the maximum possible minimal frequency is 22, it can be easily seen that the better answer doesn't exist. Other examples of correct answers: "cbcabba", "ccbbaaa" (any permutation of given answers is also correct).

In the second example query any permutation of first four letters is acceptable (the maximum minimal frequency is 11).

In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is 33).

#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	char s;
	scanf("%d",&T);
	while(T--){
		int n,k,j=0;
		scanf("%d%d",&n,&k);
			for(int i=0;i<n;i++){
				s='a'+j;
				j++;
				if(j==k)
				j=0;	
				printf("%c",s);
			}
			printf("\n");
	}
}

C. Prefixes and Suffixes

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ivan wants to play a game with you. He picked some string ss of length nn consisting only of lowercase Latin letters.

You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 11 to n−1n−1), but he didn't tell you which strings are prefixes and which are suffixes.

Ivan wants you to guess which of the given 2n−22n−2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin!

Input

The first line of the input contains one integer number nn (2≤n≤1002≤n≤100) — the length of the guessed string ss.

The next 2n−22n−2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 11 to n−1n−1 consisting only of lowercase Latin letters. They can be given in arbitrary order.

It is guaranteed that there are exactly 22 strings of each length from 11 to n−1n−1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length nn.

Output

Print one string of length 2n−22n−2 — the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The ii-th character of this string should be 'P' if the ii-th of the input strings is the prefix and 'S' otherwise.

If there are several possible answers, you can print any.

Examples

input

5
ba
a
abab
a
aba
baba
ab
aba

output

SPPSPSPS

input

3
a
aa
aa
a

output

PPSS

input

2
a
c

output

PS

Note

The only string which Ivan can guess in the first example is "ababa".

The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.

In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,vis[105]={0},c=0;
	string s[300],s1="O",s2="O",P="";
	scanf("%d",&n);
	for(int i=0;i<2*n-2;i++){
		cin>>s[i];
		if(s1.size()<s[i].size())
			s1=s[i];
		else if(s1.size()==s[i].size())s2=s[i];
	}
	for(int i=0;i<2*n-2;i++){
		if(s1.substr(0,s[i].size())==s[i])
			if(s[i]!=s2)
			c++;
	}
		if(c>=(n*2-2)/2&&s1.substr(1,s1.size()-1)==s2.substr(0,s1.size()-1))
			P=s1;
		else P=s2;
	
	for(int i=0;i<2*n-2;i++){
		if(P.substr(0,s[i].size())==s[i]&&vis[s[i].size()]!=1){
			cout << "P";
			vis[s[i].size()]=1;
		}
		else cout<<"S";
	}
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值