This page is still under construction.

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

Forming Badminton Doubles Teams

Interview

Time limit1sMemory limit1024 MB

Summary
Partition some people into groups of four to minimize the total skill gap per group, and list anyone left out; output any valid choice.
Level

Medium6 of 10

Topics
Sorting, Dynamic programming, Greedy, Array
Solved
No attempts yet

Problem

Members of the badminton club at Korea University want to play badminton. So that everyone can play at the same time and have fun, they want to form doubles teams as follows, taking each member's skill into account.

In badminton doubles, two players pair up to face another pair, so a game involves a total of four people, two on each side. Every person's badminton skill can be represented as a positive integer. For each team, define its skill gap as (maximum skill) - (minimum skill). People of similar skill should play together to have fun, so the smaller the skill gap, the more fun the game is. Apart from the skill gap, not playing badminton at all is the least fun, so as many teams as possible must be formed.

Since there are many people right now, several teams must be formed, and the sum of the skill gaps of all teams must be minimized. However, the number of participants may not be a multiple of 4, so some people may not get to play.

Write a program that, when forming teams so that the sum of the skill gaps is minimized, finds the minimum value of that sum and determines who does not get to play badminton.

Input

The first line gives the number of participants NN. (4≤N≤1054 \leq N \leq 10^5)

The second line gives NN integers m0,m1,…,mN−1m_0,m_1,\ldots ,m_{N-1} representing the badminton skills, separated by spaces. (1≤mi≤1091\leq m_i \leq 10^9)

Skills are given in order of person number, so the skill of person ii is mim_i, and numbering starts at 0.

Output

On the first line, print the minimum value of the sum of the skill gaps.

From the second line, print the numbers of the people who do not get to play badminton, one per line. If there are several valid cases, print any one of them.

Examples3

  1. Example 1

    Input
    10
    4 99 3 98 50 51 2 97 1 96
    
    Expected output
    6
    4
    5
    
  2. Example 2

    Input
    8
    5 3 1 2 24 30 27 29
    
    Expected output
    10
    
  3. Example 3

    Input
    9
    1 10 9 8 7 30 25 20 15
    
    Expected output
    18
    0