#arc123d. [arc123_d]Inc, Dec - Decomposition
[arc123_d]Inc, Dec - Decomposition
Problem Statement
Given is a sequence of integers .
Consider a pair of sequences of integers and that satisfies the following conditions:
- holds for each ;
- is non-decreasing, that is, holds for each ;
- is non-increasing, that is, holds for each .
Find the minimum possible value of $\\sum_{i=1}^N \\bigl(\\lvert B_i\\rvert + \\lvert C_i\\rvert\\bigr)$.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 -2 3
Sample Output 1
10
One pair of sequences and that yields the minimum value is:
- ,
- .
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 and that yields the minimum value is:
- ,
- .
Sample Input 3
1
-10
Sample Output 3
10
One pair of sequences and that yields the minimum value is:
- ,
- .