Under construction

Still being built. Things may change

K representatives on a line

Time limit2sMemory limit512 MB

Summary
For each K from 1 to N, place K real points on a line to minimize the total distance to all given points.
Level

Hard8 of 10

Topics
Dynamic programming, Divide and conquer, Greedy, Sorting
Solved
No attempts yet

Problem

You are given a sequence of integers a1,a2,…,aNa_1, a_2, \dots, a_N. For a positive integer KK, choose real numbers b1,b2,…,bKb_1, b_2, \dots, b_K, which do not have to be integers, so that the value of SS is as small as possible.

S=∑i=1Nmin⁡1≤j≤K∣ai−bj∣S=\sum_{i=1}^{N} \min_{1 \le j \le K} |a_i - b_j|

For every KK from 11 to NN, find the smallest possible value of SS.

Input

The first line contains a positive integer NN (1≤N≤50001 \le N \le 5000).

The second line contains the NN integers of the sequence aa, separated by spaces. Each value is between 00 and 200000200000. The sequence is not guaranteed to be sorted.

Output

Print NN numbers on one line, separated by spaces. The KK-th number is the smallest possible value of SS when the sequence bb has length KK. Every answer is an integer.

Hint

In the example you can take b={0,6,13}b = \{0, 6, 13\} for K=3K = 3, and b={0,5,9,13}b = \{0, 5, 9, 13\} for K=4K = 4.

Examples4

  1. Example 1

    Input
    5
    0 4 6 9 13
    
    Expected output
    18 10 5 2 0
  2. Example 2

    Input
    1
    0
    
    Expected output
    0
  3. Example 3

    Input
    4
    7 7 7 7
    
    Expected output
    0 0 0 0
  4. Example 4

    Input
    2
    0 200000
    
    Expected output
    200000 0