[POI2007] DRZ-Trees

题目描述

Byteasar has a cottage. Lately, he has bought $n$ trees and had them planted all in one row. Byteasar does not, however, like the order which the trees have been planted in. It particularly annoys him that tall and short ones have been mixed up, and the composition does not meet his aesthetic criteria. Byteasar has invented a disorder coefficient so as to allow the gardener to comprehend his intentions: thelower the value of the coefficient the prettier the row of trees. It is defined in the following way: $|h_1-h_2|+|h_2-h_3|+\cdots+|h_{n-1}-h_n|$, where $h_1,h_2,\cdots,h_n$ are the heights of consecutive trees in a row. Replanting is a very toilsome and cumbersome task, therefore Byteasar has ordered the gardener to replanttwo trees at the most (i.e. interchange their positions). The task of the gardener is to choose the pair to replantin a way that makes the disorder coefficient the smallest. The gardener is not sure if he has chosen the correct pair of trees and he fears he may lose his job ifhe is mistaken. Help him: for each tree calculate the minimal disorder coefficient that may be attained byswitching places with any other tree. TaskWrite a programme which: reads the height of the consecutive trees in a row from the standard input, for each tree calculates the minimal disorder coefficient that may be attained should it switch places with some other tree (or should there be no change at all), writes the outcome to the standard output. 定义一排树的不整齐程度为相邻两树的高度差的和。设树高分别为 $h _ 1, h _ 2, \cdots, h _ n$,那么不整齐程度定义为:$|h_1-h_2|+|h_2-h_3|+\cdots+|h_{n-1}-h_n|$。 请对于每个 $i$ 求出,如果只把 $i$ 和另一棵树交换高度(可以不交换),那么不整齐度最小是多少。

输入输出格式

输入格式


The first line of the standard input contains one integer $n$ ($2\le n\le 50\ 000$). The other contains $n$ integers $h_i$ ($1\le h_i\le 100\ 000\ 000$)separated by single spaces, denoting the height of the consecutive trees in the row.

输出格式


The output should consist of precisely $n$ lines. The $i$'th line should contain a single integer - the smallestdisorder coefficient attainable when considering replanting of the $i$'th tree.

输入输出样例

输入样例 #1

5
7 4 5 2 5

输出样例 #1

7
7
8
7
7