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

Copy

3
0 0 0

output

Copy

Possible
1 1 1

input

Copy

5
3 3 2 2 2

output

Copy

Possible
1 1 2 2 2

input

Copy

4
0 1 2 3

output

Copy

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.

题解:看分了几组,假如说有很多人说了有a个人和自己不同,那么就有n-a个人和自己是一组。

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std; struct node
{
int id,val;
}p[100005]; bool cmp(node x,node y)
{
return x.val<y.val;
} int ans[100005];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
p[i].id=i;
scanf("%d",&p[i].val);
}
sort(p+1,p+n+1,cmp);
//for(int t=1;t<=n;t++)
//{
//cout<<p[t].val<<" "<<p[t].id<<endl;
//}
int last = 1;
long long int sum=0;
int cnt=0;
while(1)
{ int t=last+(n-p[last].val)-1;
if(p[t].val==p[last].val)
{
cnt++;
for(int j=last;j<=t;j++)
{
ans[p[j].id]=cnt;
}
sum+=(n-p[last].val);
last=t+1;
if(t==n)break;
}
else{
printf("Impossible\n");
return 0;
}
}
if(sum!=n)
{
printf("Impossible\n");
}
else
{
printf("Possible\n");
for(int i=1;i<=n;i++)
{
printf("%d ",ans[i]);
}
} return 0;
}

最新文章

  1. 完整部署CentOS7.2+OpenStack+kvm 云平台环境(5)--问题解决
  2. xampp安装
  3. 按Enter键触发事件
  4. ARCGIS自定义下拉列表
  5. DTO概念
  6. Postman-简单使用
  7. CentOS Mysql自动备份 .txt
  8. Data Struture 之 指针
  9. OutLook中发送用户密码加密的小技巧
  10. mysql foreign key 外键
  11. 【转】unity3d的常用快捷键
  12. ThreadSafeClientConnManager的20个例子
  13. RedHat Enterprise Linu…
  14. matplotlib报错_tkinter.TclError: no display name and no $DISPLAY environment variable
  15. 一、Windows下Git的安装与配置
  16. iOS 技术篇:从使用到了解block底层原理 (一)
  17. sqlite数据导入mysql
  18. Bytom矿池接入协议指南
  19. android笔记---主界面(二)自定义actionbar环境的配置
  20. hdu 1394 Minimum Inversion Number 逆序数/树状数组

热门文章

  1. BZOJ 1660 [Usaco2006 Nov]Bad Hair Day 乱发节:单调栈
  2. Linux 查看并删除.svn目录
  3. Spring笔记01(基础知识)
  4. 51nod_1236_序列求和 V3 _组合数学
  5. P1150 Peter的烟
  6. 【Python】numpy 数组拼接、分割
  7. VirtualBox文件系统已满--磁盘扩容
  8. poj3281Dining——网络流匹配
  9. css如何改变placeholder的默认颜色值
  10. [hdu2196]Computer树的直径