Card Game#279

Card Game

1 second
128 megabytes
Very easy (≈850)

Ali and Muhammed are playing a card game. There are n cards arranged on the table, each with a different number written on it. The players take turns. Ali starts the game. On each turn, a player can take either the leftmost card or the rightmost card. A player always chooses the card with the highest number. The game continues until no cards remain. At the end of the game, find the sum of the numbers on the cards collected by Ali and Muhammed.

Input

The first line contains the number of cards on the table n~(1 \le n \le 10000) . The second line contains positive integers — each indicating the number on a card. All integers are not greater than 10^9.

Output

After the game ends, print the sum of the numbers on the cards collected by Ali and Muhammed.

Examples

Example 1

Loading
Loading