Berland Railroads

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Berland government has decided to build a system of high speed railroads in the country. There are nn cities in Berland, numbered from 11 to nn. Some pairs of cities will be connected by a high speed railroad. Travelers will be able to move by train in both directions along each road.

High speed trains are the future of transport, so it is required to create such plan of railroad construction, that it is possible to get from any city to any other using railroads. To save money it was decided to build the minimal possible number of railroads to satisfy this criteria.

The government of the ii-th city wants to support exactly d_id\_i trains. So the number of high speed railroads connecting the ii-th city to others must be exactly d_id\_i. Fortunately it turned out that d_1+d_2++d_n=2n2d\_1 + d\_2 + \ldots + d\_n = 2n - 2.

The government wants people to travel between cities using as few changes between trains as possible. You are asked to create such plan of railroads that the maximal number of changes needed to travel from a city to another was minimal.

입력

The first line of input contains an integer nn --- the number of cities in Berland (2n200,0002 \leq n \leq 200\\,000). The next line contains nn integers: d_1,d_2,,d_nd\_1, d\_2, \ldots, d\_n (1d_i<n1 \leq d\_i < n). The number of cities connected to the ii-th city must be d_id\_i for each ii. It is guaranteed that d_1+d_2++d_n=2n2d\_1 + d\_2 + \ldots + d\_n = 2n - 2.

출력

Output n1n-1 lines --- the descriptions of the railroads in the optimal plan. Each line must contain two integers s_is\_i and f_if\_i --- cities to be connected by a railroad, 1s_i,f_in1 \leq s\_i, f\_i \leq n, s_if_is\_i \neq f\_i

The number of cities connected to the ii-th city must be equal to d_id\_i for all ii. The maximum number of train changes needed to travel from a city to another must be minimal possible. If there are several optimal plans, output any of them. It is guaranteed that there is at least one plan that satisfies all conditions.

힌트

The optimal answer for the first sample test is the following:

It is possible to get from any city to any other using railroads. Each city has the required number of connected cities, for example the city 11 is connected to three cities: 22, 44 and 66 (d_1=3d\_1=3).

The maximum number of train changes needed to get from a city to another is for example for cities 33 and 55, 33 transfers are needed. First you must travel from city 33 to city 22, then from city 22 to city 11, then from city 11 to city 44, and finally from city 44 to city 55. There is no plan that requires fewer changes for all pairs of cities.