0193. Black-White Numbers

Input file name: black.in
Output file name: black.out
Time limit: 500 ms
Memory limit: 32 megabytes

You are given white integer numbers Wi (1 ≤ i ≤ n) and black integer numbers Bi (1 ≤ i ≤ n). Write a program which finds such 2n positive integers ki and li (1 ≤ i ≤ n) that ki ≠ kj∀i ≠ j, li ≠ lj∀i ≠ j, 1 ≤ ki, li ≤ n, A=Σ1 ≤ i ≤ n |Wki-Bli| will be minimal possible.

Input file

There is a single integer n (1 ≤ n ≤ 10000) on the first line. The second line contains n integers – white numbers. The third line contains n integer black numbers. All numbers do not exceed 2,000,000,000 by absolute value.

Output file

Write to the output n+1 lines. In the first line you are to write out minimal possible value of A. In the next n lines write out 2n positive integers: (i+1)-th line must contain ki and li, separated by a single space.

Examples:

black.inblack.out
1 1 21 1 1


Source: Petrozavodsk Summer 2003. Saratov SU Contest, Wednesday, August 27

Discuss       Submit a solution



Printable version