402358: GYM100738 D Degree Sequence Tree

Memory Limit:64 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Degree Sequence Treetime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard output

Serhan is a very naughty boy. He is well known to have shattered every single toy he got as a present. When asked by his parents what are his reasons for doing it he invokes countless philosophies talking about reaching the true meaning of a notion by bringing it to it's essence. In other words, he thinks learning truly occurs when something is broken apart and analyzed.

In order to cure these bad habits, his parents decided to prove him wrong by giving him a tree with N nodes as a present. Serhan's first reaction was to tear apart his new present. Yet, he was now confused. There was more to the tree than a bunch of shattered vertices, yet there those vertices stood in a complete mess. His understanding of life was now shattered. In order to retrieve the core meaning of the tree he had to build it back.

The boy seems to remember the degree of each of his vertices, but has no idea how to build the tree back, he has never build anything before. It is your responsibility to give him a way to unite the vertices to each other in order to build back the tree. If this task is impossible, output -1 and leave Serhan in eternal pain and remorse.

Input

The input contains on the first line N(1 ≤ N ≤ 200000), the number of vertices. On the next line there are N integers describing the degree of each vertex.

Output

Output N - 1 lines with 2 integers, each describing an edge of the initial tree. If there are multiple trees satisfying the degree sequence you can output any of them. If there is no such tree output -1 on a single line.

ExamplesInput
5
1 2 3 1 1
Output
1 2
2 3
3 4
3 5
Input
3
2 2 1
Output
-1

加入题单

算法标签: