This page is still under construction.

Parts of this page are still being built. What you see may change.

Robots

Time limit2sMemory limit1024 MB

Summary
Given N robots and N antennas on a line, activate antennas one at a time so each pulls its nearest remaining robot; minimize total distance moved and output an order.
Level

Hard8 of 10

Topics
Dynamic programming, Greedy, Sorting, Two pointers
Solved
No attempts yet

Problem

There are NN robots numbered from 11 through NN and NN antennas numbered from 11 through NN on a straight line. The coordinate of robot ii is aia_i and the coordinate of antenna ii is bib_i. All coordinates are distinct.

Currently all antennas are inactive. You are going to activate them one by one. When you activate an antenna, the nearest robot moves to that antenna and explodes along with it. If two robots are equally close, only the left one moves.

Find an order to activate the antennas so that the total distance the robots move is minimum.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 …\dots aNa_N

b1b_1 b2b_2 …\dots bNb_N

Output

Print the answer in the following format:

XX

p1p_1 p2p_2 …\dots pNp_N

Here, XX is the minimum total distance, and pip_i is the index of the antenna you activate in the ii-th step.

If there are multiple solutions, you can print any of them.

Constraints

  • 1≤N≤2×1051 \leq N \leq 2 \times 10^5
  • 0≤a1<a2<⋯<aN≤1090 \leq a_1 < a_2 < \dots < a_N \leq 10^9
  • 0≤b1<b2<⋯<bN≤1090 \leq b_1 < b_2 < \dots < b_N \leq 10^9
  • a1,a2,…,aN,b1,b2,…,bNa_1, a_2, \dots, a_N, b_1, b_2, \dots, b_N are all distinct.
  • All values in input are integers.

Examples1

  1. Example 1

    Input
    3
    1 2 3
    11 12 13
    
    Expected output
    30
    3 2 1