The Great Wall II
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 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 divide strategically all beacon towers into k parts where each part contains several, but at least one, consecutive beacon towers. To fully defend against the invaders, to each part a team of defenders should be assigned, the cost of which is given by the highest altitudes of beacon towers in that part.

As a historian, you are dying to know the minimum costs of assignments for every .

输入描述:

The first line contains an integer n , denoting the number of beacon towers alongside the Great Wall.

The second line contains n integers , where the i-th integer a_i is the altitude of the i-th beacon tower.

输出描述:

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

输入

复制
5
1 2 3 4 5

输出

复制
5
6
8
11
15
示例2

输入

复制
5
1 2 1 2 1

输出

复制
2
3
4
6
7