Optimal Strategy For A Game

easy
1. You are given an array(arr) of length N, where N is an even number.
2. The elements of the array represent N coins of values arr1,arr1...arrN.
3. You are playing a game against an opponent in an alternative way, where the opponent is equally smart.
4. In this game, a player selects either the first or the last coin from the row in every turn, removes it from the row permanently, and receives the value of the coin.
5. You have to find the maximum possible amount of money you can win if you make the first move.

Input Format

A number N arr1 arr2...N numbers

Output Format

Check the sample output and question video.

Constraints

2 <= N <= 1000
1 <= arr[i] <= 10^6

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
5
3
7
10
Output
15
Previous
Cut Paper Into Squares
Next
Rod Cutting

Related Questions