You and your friend are playing a game on a line of stones. Each stone has a value . Alternating turns, starting from you, the following move is performed until there are no more stones:
- If there is only one stone, take that stone.
- Otherwise, take either stone or stone .
- If stone is taken, stone becomes the new stone , stone becomes the new stone , etc.
- If stone is taken, stone becomes the new stone , stone becomes the new stone , etc.
The goal of the game is to take the stones such that the sum of stones' value is the maximum. If both of you play optimally, what is the maximum sum of the stones' value can you achieve?
Input Specification
The first line will contain the integer , the number of stones.
The second line will contain integers, , the values of stones. The first integer is the value of stone , the second is stone , etc.
Output Specification
Output the maximum sum of stones' value that you take if both you and your friend play optimally.
Sample Input
5
1 3 2 4 5
Sample Output
8
Comments