#arc123d. [arc123_d]Inc, Dec - Decomposition

[arc123_d]Inc, Dec - Decomposition

Problem Statement

Given is a sequence of integers A=(A1,ldots,AN)A = (A_1, \\ldots, A_N).

Consider a pair of sequences of integers B=(B1,ldots,BN)B = (B_1, \\ldots, B_N) and C=(C1,ldots,CN)C = (C_1, \\ldots, C_N) that satisfies the following conditions:

  • Ai=Bi+CiA_i = B_i + C_i holds for each 1leqileqN1\\leq i\\leq N;
  • BB is non-decreasing, that is, BileqBi+1B_i\\leq B_{i+1} holds for each 1leqileqN11\\leq i\\leq N-1;
  • CC is non-increasing, that is, CigeqCi+1C_i\\geq C_{i+1} holds for each 1leqileqN11\\leq i\\leq N-1.

Find the minimum possible value of $\\sum_{i=1}^N \\bigl(\\lvert B_i\\rvert + \\lvert C_i\\rvert\\bigr)$.

Constraints

  • 1leqNleq2times1051\\leq N\\leq 2\\times 10^5
  • \-108leqAileq108\-10^8\\leq A_i\\leq 10^8

Input

Input is given from Standard Input in the following format:

NN A1A_1 A2A_2 ldots\\ldots ANA_N

Output

Print the answer.


Sample Input 1

3
1 -2 3

Sample Output 1

10

One pair of sequences B=(B1,ldots,BN)B = (B_1, \\ldots, B_N) and C=(C1,ldots,CN)C = (C_1, \\ldots, C_N) that yields the minimum value is:

  • B=(0,0,5)B = (0, 0, 5),
  • C=(1,2,2)C = (1, -2, -2).

Here we have $\\sum_{i=1}^N \\bigl(\\lvert B_i\\rvert + \\lvert C_i\\rvert\\bigr) = (0+1) + (0+2) + (5+2) = 10$.


Sample Input 2

4
5 4 3 5

Sample Output 2

17

One pair of sequences BB and CC that yields the minimum value is:

  • B=(0,1,2,4)B = (0, 1, 2, 4),
  • C=(5,3,1,1)C = (5, 3, 1, 1).

Sample Input 3

1
-10

Sample Output 3

10

One pair of sequences BB and CC that yields the minimum value is:

  • B=(3)B = (-3),
  • C=(7)C = (-7).