#000011

igra

Jack and John are playing a game: on the table there are n numbers sorted in an array. First, Jack takes one number from the left or right side of the array. Then, John takes one number from the left or right side of the remaining array. They continue to alternate until there are no remaining numbers on the table. Write a program which calculates, assuming that Jack and John play optimally, the maximum sum of numbers that Jack can collect.


InputThe first line of the standard input contains a number n (n <= 128), and the second line contains n numbers from the range [0, 100].

OutputTo the standard output write just one number, the maximum sum of numbers which Jack can collect.

Input:
4
10 20 1 5

Output:
25

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.