Problem D
Forest Construction
Anton, a young mathematician, comes from the cold region that is northern Sweden. He likes it there, since there are a lot of trees. Lately, however, this has made him a bit sad, since he can’t see the forest because of all the trees. Therefore, he has asked you to construct a forest.
Since Anton is a mathematician, he doesn’t want just any forest – he wants a graph theoretical forest. A forest is a (possibly disconnected) graph without cycles – i.e., a union of disjoint trees.
Anton has already decided how many vertices he wants in his forest, as well as the degree of each vertex. Now, it is your task to construct a forest according to his wishes, or determine that no such forest exists.
Input
The first line of the input is a single integer
The next line contains
Output
The first line of output should be IMPOSSIBLE if it is impossible to construct such a forest.
Otherwise, the first line should be POSSIBLE. The next lines should then contain
two integers
Sample Input 1 | Sample Output 1 |
---|---|
3 1 1 2 |
POSSIBLE 1 3 2 3 |
Sample Input 2 | Sample Output 2 |
---|---|
2 1 2 |
IMPOSSIBLE |
Sample Input 3 | Sample Output 3 |
---|---|
3 2 2 2 |
IMPOSSIBLE |