Leonhard Euler famously solved The Seven Bridges of Königsberg problem, leading to the establishment of graph theory. Overjoyed by the creation of a new branch of mathematics, Euler decided to pose himself a problem.
First, Euler gives himself nodes and edges to build a directed graph (a directed tree with all edges pointing away from root node), labelling each node from to . The node is assigned a value, , of . After doing so, he assigns a weight, , to each edge where is equal to the sum of the values of all the nodes that would be disconnected if that edge were to be removed.
Ex: if nodes become disconnected.
Note that in the above sample , and so on.
He decides to order these edges by weight from greatest to least (decreasing order) and writes down which node the edges come from (if goes to , Euler would write down ). Unfortunately, Euler was distracted by a different mathematical problem and came back to find his graph missing. However, he still has his written notes! Can you help Euler reconstruct his original graph?
Input Specifications
The first line of input contains representing the number of nodes.
The second line of input contains integers, where is the node from which the edge came from. Edges are given in decreasing order of weight.
Output Specifications
In decreasing order of weight, output lines each representing an edge in the form a b
where and are two valid nodes and a<b
.
Sample Input
6
6 3 6 2 3
Sample Output
3 6
1 3
2 6
2 4
3 5
Explanation
Note from in the sample should be of weight not
: I believe the edge between
Comments