#P3453. [POI 2007] DRZ-Trees
[POI 2007] DRZ-Trees
Description
Byteasar has a cottage. He has bought trees and had them planted in a single row. He dislikes the current order: tall and short ones are mixed, and the arrangement does not meet his aesthetic criteria.
He defines the disorder coefficient of a row as the sum of absolute differences of heights of adjacent trees: $|h_1 - h_2| + |h_2 - h_3| + \cdots + |h_{n-1} - h_n|$, where are the heights of the trees in order.
Replanting is laborious, so at most two trees may be replanted, i.e., their positions may be swapped. For each position , determine the minimal disorder coefficient that can be achieved by swapping the tree at position with any other single tree (or by not swapping at all).
Input Format
The first line contains one integer ().
The second line contains integers (), separated by single spaces, denoting the heights of the trees in order.
Output Format
Output exactly lines. The -th line should contain a single integer: the minimal disorder coefficient attainable when considering swapping the -th tree with some other tree (or making no change).
5
7 4 5 2 5
7
7
8
7
7
5
1 2 3 4 5
4
4
4
4
4
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号