OJOnline Judge
HomeProblemsSubmissionsRankingAdmin
Sign in
← Problems/NP11

NP11Optimal Neighbour Pairing

Hardstdio★ 1800greedysortingcustom-checker
Time
2000 ms
Memory
128 MB
I/O
stdio
Tests
21 (20 hidden)
Solved
2

Optimal Neighbour Pairing

You are given 2n2n2n items with distinct integer weights. Pair every item exactly once so that the sum of the absolute weight differences within the pairs is as small as possible. Any optimal pairing is accepted.

Input

The first line contains one integer nnn, the number of pairs to create. The second line contains 2n2n2n distinct integers w1,w2,…,w2nw_1, w_2, \ldots, w_{2n}w1​,w2​,…,w2n​, the item weights.

Output

Print nnn lines. Each line must contain two 1-based indices of items forming one pair. Every index from 111 through 2n2n2n must appear exactly once, and the total pairing cost must be minimal.

Constraints

1≤n≤191 \le n \le 191≤n≤19

−300≤wi≤297-300 \le w_i \le 297−300≤wi​≤297

All weights are distinct.

Example

Input:

text
3
10 1 8 3 4 20

Output:

text
2 4
5 3
1 6

The pairs have weight differences 222, 444, and 101010, for a total cost of 161616, which is minimal.

Allowed languages

Python, C++

Samples

Sample 1

Input

3
10 1 8 3 4 20

Output

2 4
5 3
1 6

The pairing has the minimum total cost of 16.

Log in to submit a solution.

Source codeType here, or drop a file onto it
Loading editor...