Avito Cool Challenge 2018

本文探讨了三种不同的编程竞赛题目,包括最小化整数游戏、告别派对的帽子分配问题及彩色砖块的涂色方案计数。通过具体示例和代码实现,展示了算法设计与问题解决的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Definite Game

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.

He came up with the following game. The player has a positive integer nn. Initially the value of nn equals to vv and the player is able to do the following operation as many times as the player want (possibly zero): choose a positive integer xx that x<nx<n and xx is not a divisor of nn, then subtract xx from nn. The goal of the player is to minimize the value of nn in the end.

Soon, Chouti found the game trivial. Can you also beat the game?

Input

The input contains only one integer in the first line: vv (1≤v≤1091≤v≤109), the initial value of nn.

Output

Output a single integer, the minimum value of nn the player can get.

Examples

input

8

output

1

input

1

output

1

Note

In the first example, the player can choose x=3x=3 in the first turn, then nn becomes 55. He can then choose x=4x=4 in the second turn to get n=1n=1 as the result. There are other ways to get this minimum. However, for example, he cannot choose x=2x=2 in the first turn because 22is a divisor of 88.

In the second example, since n=1n=1 initially, the player can do nothing.

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	if(n<=2){
		printf("%d\n",n); 
		return 0;
	}
	printf("1\n");
} 

B. Farewell Party

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.

Chouti remembered that nn persons took part in that party. To make the party funnier, each person wore one hat among nn kinds of weird hats numbered 1,2,…n1,2,…n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.

After the party, the ii-th person said that there were aiai persons wearing a hat differing from his own.

It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let bibi be the number of hat type the ii-th person was wearing, Chouti wants you to find any possible b1,b2,…,bnb1,b2,…,bn that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105), the number of persons in the party.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤n−10≤ai≤n−1), the statements of people.

Output

If there is no solution, print a single line "Impossible".

Otherwise, print "Possible" and then nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤n1≤bi≤n).

If there are multiple answers, print any of them.

Examples

input

3
0 0 0

output

Possible
1 1 1 

input

5
3 3 2 2 2

output

Possible
1 1 2 2 2 

input

4
0 1 2 3

output

Impossible

Note

In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 11.

In the answer to the second example, the first and the second person wore the hat with type 11 and all other wore a hat of type 22.

So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.

In the third example, it can be shown that no solution exists.

In the first and the second example, other possible configurations are possible.

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn],s[maxn],c[maxn],b[maxn];
int main(){
	int n,l=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		a[i]=n-a[i];
		s[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		if(s[i]%i){
		printf("Impossible\n");
		return 0;
		}
		
	}
	printf("Possible\n");
	for(int i=1;i<=n;i++){
		if(c[a[i]]==0)
		b[a[i]]=++l;
		c[a[i]]++;
		c[a[i]]%=a[i];
		printf("%d ",b[a[i]]);
	}
}

C. Colorful Bricks

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.

There are nn bricks lined in a row on the ground. Chouti has got mm paint buckets of different colors at hand, so he painted each brick in one of those mm colors.

Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are kk bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure).

So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998244353998244353.

Input

The first and only line contains three integers nn, mm and kk (1≤n,m≤2000,0≤k≤n−11≤n,m≤2000,0≤k≤n−1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it.

Output

Print one integer — the number of ways to color bricks modulo 998244353998244353.

Examples

input

3 3 0

output

3

input

3 2 1

output

4

Note

In the first example, since k=0k=0, the color of every brick should be the same, so there will be exactly m=3m=3 ways to color the bricks.

In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 44 possible colorings.

 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P 998244353
int n,m,k,i,j,f[2005][2005];
int main()
{
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)for(f[i][0]=m,j=1;j<i;j++)f[i][j]=(f[i-1][j]+(ll)(m-1)*f[i-1][j-1])%P;
	cout<<f[n][k]<<endl;
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值