- Time limit: 2.00 s
- Memory limit: 512 MB
You are sitting in front of a roulette-style wheel with 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, . Then one line with numbers, , separated by spaces.
These numbers indicate the sums of money that are there in each sector, in euros, in the clockwise order. For example, is the sum in the sector between and , and is the sector between and .
All values are nonnegative integers.
Output
Print out one number, , which is the highest possible amount of money in euros that you can get.
Constraints
Example
Input:
6 1 1000 2 3 1024 4
Output:
2021
Explanation:
You can label the sectors with red, black, red, green, black, green (in this order, starting with sector ), and this way gain euros and lose euros, with the total net gain euros.