302761: CF534D. Handshakes
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Handshakes
题意翻译
给出$n$个数 $a_i$ 要求$a$的一个排列$s$满足: $s_1$=0 , $s_{i-1}$-$s_i$=$3k-1$($k>=0$)题目描述
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.输入输出格式
输入格式
The first line contains integer $ n $ ( $ 1<=n<=2·10^{5} $ ) — the number of students who came to CTOP. The next line contains $ n $ integers $ a_{1},a_{2},...,a_{n} $ ( $ 0<=a_{i}<n $ ), where $ a_{i} $ is the number of students with who the $ i $ -th student shook hands.
输出格式
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".
输入输出样例
输入样例 #1
5
2 1 3 0 1
输出样例 #1
Possible
4 5 1 3 2
输入样例 #2
9
0 2 3 4 1 1 0 2 2
输出样例 #2
Possible
7 5 2 1 6 8 3 4 9
输入样例 #3
4
0 2 1 1
输出样例 #3
Impossible