CSES - Aalto Competitive Programming 2024 - wk3 - Mon - Wheel of fortune
  • Time limit: 2.00 s
  • Memory limit: 512 MB

You are sitting in front of a roulette-style wheel with NN sectors, and each sector is labeled with a sum of money.

Instead of spinning the wheel, the TV show host is offering you a possibility of winning a much larger sum of money. You have got black, red, and green tokens, and you have to place them on the sectors so that each sector gets one token and adjacent sectors have different colors. Now you will get money as follows:

For each black token you gain the sum of money in the sector.
For each red token you lose the sum of money in the sector.
The sectors with green tokens are ignored.
Now you need to find the strategy that gives the highest amount of money.

Input

First a line with one number, NN. Then one line with NN numbers, C1,C2,,CNC_1,\,C_2,\ldots,\,C_N, separated by spaces.

These numbers indicate the sums of money that are there in each sector, in euros, in the clockwise order. For example, C2C_2 is the sum in the sector between C1C_1 and C3C_3, and CNC_N is the sector between CN1C_{N-1} and C1C_1.

All values CiC_i are nonnegative integers.

Output

Print out one number, XX, which is the highest possible amount of money in euros that you can get.

Constraints

  • 3N1053 \leq N \leq 10^5
  • 0Ci1050 \leq C_i \leq 10^5

Example

Input:

6
1 1000 2 3 1024 4

Output:

2021

Explanation:

You can label the 66 sectors with red, black, red, green, black, green (in this order, starting with sector 11), and this way gain 1000+10241000 + 1024 euros and lose 1+21 + 2 euros, with the total net gain 20212021 euros.