Dance Partners on the Pier (easy version)
n dancers stand in a line along the pier, numbered 1 to n from left to right. Dancer i has skill level a_i.
While at least two dancers are still in the line, the following happens:
- Among all pairs of dancers who currently stand next to each other, pick the pair whose skill levels differ the least, that is, with the smallest
|a_x − a_y|. If several pairs share the smallest difference, pick the leftmost one. - Those two dancers leave the line to dance together, and the dancers on either side of the gap step closer, so they become neighbours.
If n is odd, one dancer is left standing at the end.
Print the pairs in the order they leave the line.
Input
The first line contains an integer n (2 ≤ n ≤ 2000), the number of dancers.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9), the skill levels from left to right.
Output
Print ⌊n/2⌋ lines. The k-th line describes the k-th pair to leave: the original numbers of its two dancers, the left one first, separated by a space.
Notes
In the first example, the neighbouring differences are 4 3 2 3 2. The smallest, 2, appears twice, so the leftmost pair, dancers 3 and 4, leaves first. Dancers 2 and 5 (skills 1 and 9) are now neighbours. The line is 5 1 9 7, and the closest pair is dancers 5 and 6. Finally dancers 1 and 2 leave.
In the second example, dancers 3 and 4 leave first. Their departure makes dancers 2 and 5 neighbours, and with a difference of 1 they are the next pair. Dancer 1 is left standing.