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?
The first line of the input contains a single integer n (1 ≤ n ≤ 1000).
The next line contains n space-separated integers (1 ≤ ≤ ).
The program should print the maximum sum you can collect.
3 2 10 4
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