Berland Railroads
Time limit1sMemory limit512 MB
Given the required railroad count d_i for each of n cities, build a connected tree with exactly those degrees that minimizes the maximum number of train changes.
Problem
The Berland government has decided to build a system of high speed railroads in the country. There are cities in Berland, numbered from to . Some pairs of cities will be connected by a high speed railroad. Travelers can move by train in both directions along each railroad.
High speed trains are the future of transport, so the plan must allow travel from any city to any other city by rail. To save money, the government builds the fewest railroads that satisfy this condition.
The government of city wants to support exactly trains. That is, exactly railroads must connect city to other cities. It is known that .
The government wants people to change trains as few times as possible. Build the plan so that the maximum number of changes needed to travel from one city to another is as small as possible.
Input
The first line contains an integer , the number of cities (). The next line contains integers (). City must be connected to exactly other cities. It is guaranteed that .
Output
Print lines describing the railroads in the optimal plan. Each line contains two integers and , the cities to connect (, ). The number of railroads at city must equal for every . The maximum number of changes needed to travel between any two cities must be as small as possible. If several plans are optimal, print any of them. It is guaranteed that at least one valid plan exists.
Hint
The optimal answer for the first sample is shown below.

City 1 is connected to three cities: 2, 4, and 6 (). The maximum number of changes is 3, for cities 3 and 5. Travel from city 3 to city 2, then from city 2 to city 1, then from city 1 to city 4, and finally from city 4 to city 5. No plan requires fewer changes for every pair of cities.