- Time limit: 1.00 s
- Memory limit: 512 MB
A Prüfer code of a tree of nodes is a sequence of integers that uniquely specifies the structure of the tree.
The code is constructed as follows: As long as there are at least three nodes left, find a leaf with the smallest label, add the label of its only neighbor to the code, and remove the leaf from the tree.
Given a Prüfer code of a tree, your task is to construct the original tree.
Input
The first input line contains an integer : the number of nodes. The nodes are numbered .
The second line contains integers: the Prüfer code.
Output
Print lines describing the edges of the tree. Each line has to contain two integers and : there is an edge between nodes and . You can print the edges in any order.
Constraints
Example
Input:
5 2 2 4
Output:
1 2 2 3 2 4 4 5