Loading [MathJax]/jax/output/CommonHTML/jax.js


Double Flip

Description

There is an array A of length N, where N is even. In one operation, you can partition the array into two (non-empty) parts and reverse those two parts. More formally, we choose an index i (1i<N) then we change the array into [Ai,Ai1,,A1,AN,AN1,,Ai+1].

Define the cost of the array as Ni=1(1)i+1Ai=A1A2+A3A4+AN.

Find the maximum cost of the array after some (possibly zero) operations.

Constraints

  • 2N100000
  • 109Ai109
  • N is even.

Input

N
A1 A2 … AN

Output

An integer representing the maximum cost.

Sample Input 1

2
123 456

Sample Output 1

-333

Sample Input 2

4
-1 1 -1 1

Sample Output 2

4

Explanation

In the first sample, A=[123,456]. Since N=2, the only valid operation is using i=1, but after performing this operation, the array is unchanged. So the maximum cost of the array is 123456=333.

In the second sample, A=[1,1,1,1]. After performing an operation with i=2, the array becomes [1,1,1,1]. The final cost of the array is 1(1)+1(1)=4 and we can show that this is the maximum possible cost.



Submitting .cpp to 'Double Flip'


You're not logged in! Click here to login

Time Limit: 1 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: TROC 24 (errorgorn)

Subtask Score
1 100