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. CodeForces 543A - Writing Code DP 完全背包

    有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后 ...

  2. .Net Core 环境搭建

    .Net Core 系列:1.环境搭建 前言: 2016年6月28日微软宣布发布 .NET Core 1.0.ASP.NET Core 1.0 和 Entity Framework Core 1.0. ...

  3. CSS高级技巧 图标字体ICONFONT的使用方法视频

    图标字体  iconfont 这是一种字体,它跟svg 有很大 相似点   它是矢量的,放大缩小不失真的.很且很小. 我们把它成字看来. 字体 在 从ie4就开始支持的.  兼容性很好 唯一麻烦的地方 ...

  4. 说服式设计(persuasive design)的行为模型

    转自:http://www.sharetk.com/html/ued/User-Research/1404.html 一 模型简介 BJ Fogg提出了一个新的理解人类行为的模型,他称之为Fogg b ...

  5. Webservice-WSDL详解(三)

    怎样向别人介绍WS的功能呢?一般咱们会写接口文档,亦或口头告诉使用的人.这些方式都存在问题:其中一个我上篇中说过,客户端是无法直接使用服务端接口的:二是程序员在电脑前,想使用WS时,他们的工具(如Ec ...

  6. Automake创建项目

    autoconf和automake可以方便的构建linux下项目,一个简单的automake项目实例,麻雀虽小五脏俱全,以后无外乎在这基础上扩展相应的宏完善而已. .首先建立项目目录树 )创建目录树 ...

  7. 查看htmlView

    1.视图 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too ...

  8. 三种LVS负载均衡技术的优缺点----负载均衡调度算法

    三种LVS负载均衡技术的优缺点归纳以下表: VS/NATVS/TUNVS/DR 服务器操作系统任意支持隧道多数(支持Non-arp) 服务器网络私有网络局域网/广域网局域网 服务器数目(100M网络) ...

  9. ubuntu 12.04 安装sublime2

    add-apt-repository ppa:webupd8team/sublime-text-2 apt-get update apt-get install sublime-text 安装控制器: ...

  10. haproxy /admin跳转 不会在接口上再次加上admin

    http://www.xx.com/admin/api/menu [root@wx03 mojo]# cat test.pl use Mojolicious::Lite; use JSON qw/en ...