The Great Wall 2
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Beacon towers are built throughout and alongside the Great Wall. There was once a time when there were n beacon towers built from west to east for defending against the invaders. The altitude of the i-th beacon tower, based on historical records, is a_i.

The defenders strategically divide all beacon towers into k parts where each part contains several, but at least one, consecutive beacon towers. The scale of an individual part is given by the difference between the highest and the lowest altitudes of beacon towers, and the most relaxable partition minimizes the sum of scales of all parts.

As a historian, you are dying to know the minimum sums of scales for every k = 1, 2, \ldots, n.

输入描述:

The first line contains an integer n (1 \leq n \leq 5\,000), denoting the number of beacon towers alongside the Great Wall.

The second line contains n integers a_1, a_2, \ldots, a_n, where the i-th integer a_i (1 \leq a_i \leq 10^5) is the altitude of the i-th beacon tower.

输出描述:

Output n lines, the i-th of which contains an integer indicating the minimum sum for k = i.
示例1

输入

复制
5
1 2 3 4 5

输出

复制
4
3
2
1
0
示例2

输入

复制
5
1 2 1 2 1

输出

复制
1
1
1
1
0