You are given an array a1,a2,...,an. In one move, you can select an element ai and flip its sign (that is, perform ai:=−ai).
Let diff([x1,x2,...,xk]) be the number of distinct elements in an array x of length k.
If we perform the aformentioned moves optimally, what is the maximum possible value of:
i=1∑nj=i∑ndiff([ai,ai+1,...,aj])Note: You do not have to minimize the number of moves.
The first line of input contains a single integer n (1≤n≤3⋅105) — the length of array a.
The second line of input contains n integers a1,a2,…,an (−109≤ai≤109) — the elements of array a.
Output
The first line of output contains the maximum possible value of ∑diff([ai,ai+1,...,aj]), after performing the sign flipping operations optimally.
Example 1
stdin
4
1 1 0 -1
stdout
19
Note
If we flip the signs of a2 and a4, the resulting array will be [1,−1,0,1]. Therefore:
- diff([1])=1
- diff([1,−1])=2
- diff([1,−1,0])=3
- diff([1,−1,0,1])=3
- diff([−1])=1
- diff([−1,0])=2
- diff([−1,0,1])=3
- diff([0])=1
- diff([0,1])=2
- diff([1])=1
The sum of all diff's is equal to 1+2+3+3+1+2+3+1+2+1=19, which is the maximum possible value.
In the second testcase, regardless of how many operations we will perform, a will remain equal to [0,0,0].
Therefore, diff([ai,ai+1,...,aj]) is equal to 1, for all 1≤i≤j≤n. Since there are 6 subarrays, the answer is equal to 6⋅1=6.
Example 2
stdin
3
0 0 0
stdout
6
Example 3
stdin
15
2 -2 0 1 -3 0 0 3 1 -1 -4 0 -1 -2 3
stdout
510