Letβs play a game. You are given n positive integers (n is even). On each step, you are allowed to remove a number from the beginning or the very end of the sequence and keep it to yourself. I (the computer) will remove the largest among the first and the last elements in the sequence. In case those are equal, Iβll remove the first one. We will take turns until there are no items left on the list.
If you are the one starting the game, what would be the maximum sum of numbers you can collect?
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000).
The next line contains n space-separated integers (1 β€ β€ ).
Output
The program should print the maximum sum you can collect.
Examples
Input
Output
4
3 2 10 4
13
Explanation
You take the first 3 β 2 10 4
The computer takes the 4 β 2 10
You take the 10 β 2
The computer takes the 2 β Youβve collected 3 + 10 = 13