#Lutece1571. Deal W1th The Number
Deal W1th The Number
Migrated from Lutece 1571 Deal W1th The Number
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
There is a sequence which contains numbers .
Every time you can choose a number , delete it from the sequence and you will gain scores. If is the first or last number in the sequence, you will gain scores.
After that, merge the left part and the right part of the rest of the numbers, they will form a new sequence with new indexes, and you can do the same operation on it.
What's the maximum sum scores you can gain at last?
Input
The first line contains an integer .
The second line contains integers .
, .
Output
Print the maximum sum scores you can gain.
Samples
4
1 4 3 2
3
Note
In the sample, scores will be gained if number is deleted first and number is deleted then; scores will be gained if number is deleted first and number is deleted then. So the answer is .
Resources
The 15th UESTC Programming Contest Final