Under construction

Still being built. Things may change

Symmetric Mountains

Interview

Time limit1sMemory limit1024 MB

Summary
For each crop length, finds the minimum sum of height differences between mirrored mountain pairs over all consecutive crops of that length.
Level

Medium4 of 10

Topics
Brute force, Array
Solved
No attempts yet

Problem

Rebecca is a tour guide and is trying to market the Rocky Mountains for her magazine. She recently took a picture of NN mountains, where the ii-th mountain from the left has height hih_i. She will crop this picture for her magazine by possibly removing some mountains from the left side and possibly removing some mountains from the right side. A crop consists of consecutive mountains from the ll-th to the rr-th mountain, where l≤rl \le r. Rebecca wants the most symmetric crop.

The asymmetric value of a crop is the sum of ∣hl+i−hr−i∣|h_{l+i} - h_{r-i}| for all 0≤i≤r−l20 \le i \le \frac{r-l}{2}. In other words, pair the mountains from the outside in toward the center, compute the absolute height difference of each pair, and add them up.

Rebecca does not know how wide the picture needs to be. For every possible crop length, find the asymmetric value of the most symmetric crop, which is the crop with the minimum asymmetric value.

Input

The first line contains an integer NN, the number of mountains. The second line contains NN space-separated integers, where the ii-th integer is hih_i.

Output

Print on one line NN space-separated integers. The ii-th integer is the asymmetric value of the most symmetric crop of length ii.

Constraints

1≤N≤5 0001 \le N \le 5\,000

0≤hi≤1050 \le h_i \le 10^5

Examples2

  1. Example 1

    Input
    7
    3 1 4 1 5 9 2
    
    Expected output
    0 2 0 5 2 10 10
    
  2. Example 2

    Input
    4
    1 3 5 6
    
    Expected output
    0 1 3 7