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 integersa1, 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

Hint

In the first sample from the statement the order of events could be as follows:

  • student 4 comes in (a4 = 0), he has no one to greet;
  • student 5 comes in (a5 = 1), he shakes hands with student 4;
  • student 1 comes in (a1 = 2), he shakes hands with two students (students 4, 5);
  • student 3 comes in (a3 = 3), he shakes hands with three students (students 4, 5, 1);
  • students 4, 5, 3 form a team and start writing a contest;
  • student 2 comes in (a2 = 1), he shakes hands with one student (number 1).

In the second sample from the statement the order of events could be as follows:

  • student 7 comes in (a7 = 0), he has nobody to greet;
  • student 5 comes in (a5 = 1), he shakes hands with student 7;
  • student 2 comes in (a2 = 2), he shakes hands with two students (students 7, 5);
  • students 7, 5, 2 form a team and start writing a contest;
  • student 1 comes in(a1 = 0), he has no one to greet (everyone is busy with the contest);
  • student 6 comes in (a6 = 1), he shakes hands with student 1;
  • student 8 comes in (a8 = 2), he shakes hands with two students (students 1, 6);
  • student 3 comes in (a3 = 3), he shakes hands with three students (students 1, 6, 8);
  • student 4 comes in (a4 = 4), he shakes hands with four students (students 1, 6, 8, 3);
  • students 8, 3, 4 form a team and start writing a contest;
  • student 9 comes in (a9 = 2), he shakes hands with two students (students 1, 6).

In the third sample from the statement the order of events is restored unambiguously:

  • student 1 comes in (a1 = 0), he has no one to greet;
  • student 3 comes in (or student 4) (a3 = a4 = 1), he shakes hands with student 1;
  • student 2 comes in (a2 = 2), he shakes hands with two students (students 1, 3 (or 4));
  • the remaining student 4 (or student 3), must shake one student's hand (a3 = a4 = 1) but it is impossible as there are only two scenarios: either a team formed and he doesn't greet anyone, or he greets all the three present people who work individually.
 #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + ;
int q[N], n;
stack<int> s[N];
int main()
{
int a;
scanf("%d", &n);
for(int i = ; i <= n; ++i)
scanf("%d", &a), s[a].push(i); int p = , i = ;
while()
{
if(!s[i].empty())q[p++] = s[i++].top();
else
{
if(i < ) break;
s[--i].pop(), s[--i].pop(), s[--i].pop();
}
}
if(p == n)
{
puts("Possible");
for(int i = ; i < n - ; ++i)
printf("%d ", q[i]);
printf("%d\n", q[n - ]);
}
else puts("Impossible");
return ;
}

shakes hands的更多相关文章

  1. 每日英语:Skull Shakes Up Human Family Tree

    A newly discovered 1.8 million-year-old skull offers evidence that humanity's early ancestors emerge ...

  2. 关于如何通过定义自己的CameraManager来控制视角

    2016.8.30 发现了这个函数,可以直接获得摄像机的位置和旋转. Controller->GetPlayerViewPoint(CamLoc, CamRot); 最近看了几天PlayerCa ...

  3. How To Handle a Loss of Confidence in Yourself

    Do you feel like you've lost confidence in yourself? Have you had strong self doubts? Perhaps you we ...

  4. Web开发中20个很有用的CSS库

    来源: 微信公众号文章 在过去的几年中,CSS已经成为一大部分开发者和设计者的最爱,因为它提供了一系列功能和特性.每个月都有无数个围绕CSS的工具被开发者发布以简化WEB开发.像CSS库,框架,应用这 ...

  5. resignFirstResponder

    What is this resignFirstResponder business? Here is the short version:Some view objects are also con ...

  6. Web 开发中 20 个很有用的 CSS 库

    转自:http://www.oschina.net/translate/css-libraries-for-developers 在过去的几年中,CSS已经成为一大部分开发者和设计者的最爱,因为它提供 ...

  7. 越狱Season 1- Episode 18: Bluff

    Season 1, Episode 18: Bluff -Michael: Scofield Scofield Michael Scofield Michael Scofield -Patoshik: ...

  8. TEdit,TMemo背景透明

    The component below works perfectly, except for the following problem: 1) Saves the component below ...

  9. iOS Developer Libray (中文版)-- Defining Classes 定义类

    该篇是我自己学习iOS开发时阅读文档时随手记下的翻译,有些地方不是很准确,但是意思还是对的,毕竟我英语也不是很好,很多句子无法做到准确的字词翻译,大家可以当做参考,有错误欢迎指出,以后我会尽力翻译的更 ...

随机推荐

  1. Android:WebView(慕课网)

    使用webview最重要的三点: 1 WebView加载本地资源(webView.loadUrl("file:///android_asset/example.html");) 2 ...

  2. 基于springmvc的简单增删改查实现---中间使用到了bean validation

    package com.kite.controller; import java.util.HashMap; import java.util.Map; import javax.validation ...

  3. zookeeper perl 版本需求

    [root@wx03 ~]# perl -v This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-linux Cop ...

  4. 一步一步重写 CodeIgniter 框架 (5) —— 实现Controller,并加载Model

    CodeIgniter 框架采用MVC模式,而MVC模式中起纽带作用的就是C(控制器),在控制器的中通过加载模型获得数据,将数据传到视图中进行展示.本课将实现在控制器中加载模型. 1. 控制器的实现 ...

  5. hdu1853解题报告

    题意和解决回路匹配的思路如同hdu3488 (这里我第一次想到最短路,但是对于有回路这个不知道怎么处理,后来看了别人的解题报告才知道KM匹配,但是看到KM之后就自己想...想了很久....还是不知道回 ...

  6. C#验证码的另一种操作方法

    sb = new StringBuilder(); char c = '0'; string s = ""; for (int i = 0; i < 4; i++) { Ra ...

  7. ant学习记录(复制-移动-删除-依赖综合测试)+fileset

    <?xml version="1.0"?> <project name="targetStudy" default="mkdir&q ...

  8. Mac编程的官方文档(类似MSDN)

    https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammin ...

  9. asp.net 生成、解析条形码和二维码

    原文 asp.net 生成.解析条形码和二维码 一.条形码 一维码,俗称条形码,广泛的用于电子工业等行业.比如我们常见的书籍背面就会有条形码,通过扫描枪等设备扫描就可以获得书籍的ISBN(Intern ...

  10. 刘汝佳黑书 pku等oj题目

    原文地址:刘汝佳黑书 pku等oj题目[转]作者:小博博Mr 一.动态规划参考资料:刘汝佳<算法艺术与信息学竞赛><算法导论> 推荐题目:http://acm.pku.edu. ...