You are given vertices. Vertex is located at coordinate on a line and has a required degree .
Choose edges between these vertices so that they form a tree and the degree of every vertex is exactly .
The cost of an edge connecting vertices and is . The total cost of a tree is the sum of the costs of its edges.
Construct a tree with the minimum possible total cost. If there are multiple optimal trees, you may output any of them.
For each test case, output exactly edges of a tree with the required degrees and minimum total cost. Each line contains the indices of the two endpoints of one edge.
You may print the edges in any order and the endpoints of each edge in either order. Do not print the total cost or the number of edges.
The only possible tree has the edge , whose cost is .
The printed edges give degrees and total cost . Vertices and must be adjacent, and each must be connected to one of the two leaves. The other possible assignment of the leaves has cost , so the printed tree is optimal.
Vertex must be connected to every other vertex. This is the only possible tree, and its cost is .
The printed tree is the path , with total cost . Every tree must connect vertices and , which alone requires a path of cost at least .
The printed tree is the path , with total cost . Every valid tree is a path from vertex to vertex and must visit vertices and . Visiting vertex before vertex costs at least ; visiting them in the opposite order costs at least .