QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#12687. 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: the lower 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|+…+|h_{n-1}-h_n|$, where h1h2,…,hn are the heights of consecutive trees in a row.

Replanting is a very toilsome and cumbersome task, therefore Byteasar has ordered the gardener to replant two trees at the most (i.e. interchange their positions). The task of the gardener is to choose the pair to replant in 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 if he is mistaken. Help him: for each tree calculate the minimal disorder coefficient that may be attained by switching places with any other tree.

Write 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.

Input

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

Output

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

Example

Input

5
7 4 5 2 5

Output

7
7
8
7
7

Hints

In the first example a value 7 of the disorder coefficient may be attained by replanting trees 1 and 4, 2 and 5 or 4 and 5. So, by replanting any of the aforementioned trees (1,2,4,5) and its counterpart a disorder coefficient of value 7 may be obtained. Only for tree 3 the best possible result is greater - it is 8. In the second example any replanting increases the value of the disorder coefficient, so no change should take place; all disorder coefficients have the initial value (4).

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.