#abc307g. [abc307_g]Approximate Equalization

[abc307_g]Approximate Equalization

Problem Statement

You are given an integer sequence of length NN: A=(A1,A2,ldots,AN)A=(A_1,A_2,\\ldots,A_N).

Takahashi can perform the following two operations any number of times, possibly zero, in any order.

  • Choose an integer ii such that 1leqileqN11\\leq i\\leq N-1, and decrease AiA_i by 11 and increase Ai+1A_{i+1} by 11.
  • Choose an integer ii such that 1leqileqN11\\leq i\\leq N-1, and increase AiA_i by 11 and decrease Ai+1A_{i+1} by 11.

Find the minimum number of operations required to make the sequence AA satisfy the following condition:

  • lvertAiAjrvertleq1\\lvert A_i-A_j\\rvert\\leq 1 for any pair (i,j)(i,j) of integers between 11 and NN, inclusive.

Constraints

  • 2leqNleq50002 \\leq N \\leq 5000
  • lvertAirvertleq109\\lvert A_i \\rvert \\leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN A1A_1 A2A_2 ldots\\ldots ANA_N

Output

Print a single line containing the minimum number of operations required to make the sequence AA satisfy the condition in the problem statement.


Sample Input 1

3
2 7 6

Sample Output 1

4

You can make AA satisfy the condition with four operations as follows.

  • Choose i=1i=1, and increase A1A_1 by 11 and decrease A2A_2 by 11, making A=(3,6,6)A=(3,6,6).
  • Choose i=1i=1, and increase A1A_1 by 11 and decrease A2A_2 by 11, making A=(4,5,6)A=(4,5,6).
  • Choose i=2i=2, and increase A2A_2 by 11 and decrease A3A_3 by 11, making A=(4,6,5)A=(4,6,5).
  • Choose i=1i=1, and increase A1A_1 by 11 and decrease A2A_2 by 11, making A=(5,5,5)A=(5,5,5).

This is the minimum number of operations required, so print 44.


Sample Input 2

3
-2 -5 -2

Sample Output 2

2

You can make AA satisfy the condition with two operations as follows:

  • Choose i=1i=1, and decrease A1A_1 by 11 and increase A2A_2 by 11, making A=(3,4,2)A=(-3,-4,-2).
  • Choose i=2i=2, and increase A2A_2 by 11 and decrease A3A_3 by 11, making A=(3,3,3)A=(-3,-3,-3).

This is the minimum number of operations required, so print 22.


Sample Input 3

5
1 1 1 1 -7

Sample Output 3

13

By performing the operations appropriately, with 1313 operations you can make A=(0,0,1,1,1)A=(0,0,-1,-1,-1), which satisfies the condition in the problem statement. It is impossible to satisfy it with 1212 or fewer operations, so print 1313.