~/algor $ cat problems/dp-chetlardan-olish
Taking from the ends
$n$ cards with numbers lie in a row on a table. Two players move in turn, the first player starts: on each move a player takes the card at the left or right end of the row, and its number is added to their score. The game ends when the cards run out. The first player tries to make the difference between their score and the second player's score as large as possible, and the second player tries to make it as small as possible. What is this difference if both play optimally?
Input
The first line contains a positive integer $n$. The second line contains $n$ positive integers — the numbers on the cards.
Output
One integer — the difference between the scores of the first and second players.
Note
$1 \le n \le 3000$
$1 \le a_{i} \le 10^{9}$
Examples
4 10 80 90 30
10
1 7
7