Under construction

Still being built. Things may change

Post Office 3

Time limit1sMemory limit1024 MB

Summary
Pick P of V village positions on a circular road of length L for post offices, minimizing the total distance from each village to its nearest one.
Level

Medium6 of 10

Topics
Dynamic programming, Sorting, Prefix sum
Solved
No attempts yet

Problem

A circular road with circumference L runs past V villages. The road is a circle of integer positions from 0 to L-1, and each village is placed at an integer coordinate on it. Several villages may share the same position. The distance between villages at coordinates x and y is min⁡(∣x−y∣,L−∣x−y∣)\min(|x-y|, L-|x-y|).

You want to build P post offices at village locations. Not every village gets one. Choose P of the V villages and build a post office at each chosen position. Each village is served by the nearest post office. Minimize the sum of distances from every village to its nearest post office.

Input

The first line contains three integers V, P, and L. (1≤P≤V≤2501 \le P \le V \le 250, 1≤L≤10121 \le L \le 10^{12})

The second line contains V integers, the coordinates of the villages. The coordinates are sorted in non-decreasing order, and each lies between 0 and L-1, inclusive.

Output

On the first line, print S, the minimum possible sum of distances from each village to its nearest post office.

On the second line, print P integers, the positions of the villages where the post offices are built, in non-decreasing order.

Examples2

  1. Example 1

    Input
    10 5 200
    1 2 3 6 7 9 11 22 44 50
    
    Expected output
    9
    2 7 22 44 50
    
  2. Example 2

    Input
    10 5 51
    1 2 3 6 7 9 11 22 44 50
    
    Expected output
    8
    1 6 9 22 44