Description

On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in stayed in CTOP until the end of the day and never left.

At any time any three students could join together and start participating in a team contest, which lasted until the end of the day. The team did not distract from the contest for a minute, so when another student came in and greeted those who were present, he did not shake hands with the members of the contest writing team. Each team consisted of exactly three students, and each student could not become a member of more than one team. Different teams could start writing contest at different times.

Given how many present people shook the hands of each student, get a possible order in which the students could have come to CTOP. If such an order does not exist, then print that this is impossible.

Please note that some students could work independently until the end of the day, without participating in a team contest.

Input

The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.

Output

If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the j-th student. If there are multiple answers, print any of them.

If the sought order of students doesn't exist, in a single line print "Impossible".

Sample Input

Input
5
2 1 3 0 1
Output
Possible
4 5 1 3 2
Input
9
0 2 3 4 1 1 0 2 2
Output
Possible
7 5 2 1 6 8 3 4 9
Input
4
0 2 1 1
Output
Impossible

 
题意:有n个人进一个房间,如果进来的时候,里面有人,他要与每个人都握一次手,当房间里的人数大于等于三人的时候,其中有三个人可以组队离开,现在给出每个人进来时握手的次数,要求输出进来的顺序,如果方案不唯一,任意输出
 
思路:我们可以直接模拟暴力输出,握手次数决定了顺序
 
 
 
 
 
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stack>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <vector>
  9. #include <math.h>
  10. #include <algorithm>
  11. using namespace std;
  12. #define ls 2*i
  13. #define rs 2*i+1
  14. #define up(i,x,y) for(i=x;i<=y;i++)
  15. #define down(i,x,y) for(i=x;i>=y;i--)
  16. #define mem(a,x) memset(a,x,sizeof(a))
  17. #define w(a) while(a)
  18. #define LL long long
  19. const double pi = acos(-1.0);
  20. #define Len 63
  21. #define mod 19999997
  22. const int INF = 0x3f3f3f3f;
  23. int n,a[300000],ans[300000],len;
  24. vector<int> vec[300000];
  25. int main()
  26. {
  27. int i,j,k;
  28. scanf("%d",&n);
  29. {
  30. len = 0;
  31. up(i,1,n)
  32. {
  33. scanf("%d",&a[i]);
  34. vec[a[i]].push_back(i);
  35. }
  36. int now = 0,flag = 1;
  37. up(i,1,n)
  38. {
  39. w(now>=0 && vec[now].size()==0)
  40. now-=3;
  41. if(now<0)
  42. {
  43. flag = 0;
  44. break;
  45. }
  46. ans[len++] = vec[now].back();
  47. vec[now++].pop_back();
  48. }
  49. if(flag)
  50. {
  51. printf("Possible\n");
  52. printf("%d",ans[0]);
  53. up(i,1,len-1)
  54. printf(" %d",ans[i]);
  55. printf("\n");
  56. }
  57. else
  58. printf("Impossible\n");
  59. }
  60. return 0;
  61. }

CodeForces 534D Program B的更多相关文章

  1. 【codeforces 534D】Handshakes

    [题目链接]:http://codeforces.com/contest/534/problem/D [题意] n个人依次进入一个房间; 进进来的人会和房间里面没有组队的人握一次手; (这里的握手只计 ...

  2. CodeForces 468A Program F

    Description Little X used to play a card game called "24 Game", but recently he has found ...

  3. CodeForces 540C Program D

    Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...

  4. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  5. Codeforces Round #443 (Div. 1) A. Short Program

    A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...

  6. Codeforces Round #879 (Div. 2) C. Short Program

    题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...

  7. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  8. Codeforces Round #443 (Div. 2) C. Short Program

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces 879C/878A - Short Program

    传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...

随机推荐

  1. IntelliJ IDEA 学习(六)内存设置

    小伙伴们经常会发现,在开发的时候,经常遇到内存被占满,导致异常卡顿,有时候提示内存溢出,这时可以通过设置xmx来改善.不过切记最好不要超过内存的1/4 打开 IDEA 安装目录,看到有一个 bin 目 ...

  2. Asp.net_Webservice返回json

    [WebMethod] public List<PictureManager> LoadPictureOne() { dataDataContext context = new dataD ...

  3. SO_REUSEADDR 和 SO_REUSEPORT

    大部分内容来自stackoverflow上的回答:Socket options SO_REUSEADDR and SO_REUSEPORT, how do they differ? Do they m ...

  4. eclipse 新建 maven 项目 步骤(初级入门新手)

    安装 maven(百度) 和在eclipse 中svn(上一篇) 修改 maven 本地仓库 eclipse 属性 maven--> installations-->添加新的 自定义安装的 ...

  5. ARPG游戏技能系统设计

    ARPG游戏的技能的前端表现, 主要指的是人物动作和特效表现, 从普遍意义上讲,大致可以分为三个阶段:起手.飞行.碰撞(爆炸). [特效可见性判断] 1.[attacker & victim] ...

  6. C++/C#中堆栈、对象内存模型、深浅拷贝、Array.Clone方法

    转载自:http://blog.csdn.net/jarvischu/article/details/6425534 目录 1.      C++/C#中对象内存模型................. ...

  7. Azure平台 对Twitter 推文关键字进行实时大数据分析

    Learn how to do real-time sentiment analysis of big data using HBase in an HDInsight (Hadoop) cluste ...

  8. 一些用于数据整理的excel函数

    我们经常要从外部数据源(如数据库.文本文件或网页等)将数据导入excel中,但是此类数据往往比较混乱,无法满足我们的要求,因此在进行数据分析之前,需要将这些数据进行整理清洗,excel由于将数据的管理 ...

  9. python读取指定内存的内容

    import ctypes as ct t = ct.string_at(0x211000, 20) # (addr, size) print t 最好不要用解释性语言来开发底层,一般用C.

  10. Java 基础知识点(必知必会其一)

    如何将字符串转换为数字? package Day_2; /** * @author Administrator * 功能: 如何将字符串转换为数字? */ public class StringToI ...