Huseyn and Yaroslav play cards. There are cards in a row on the table with different numbers written on them. They take turns. Huseyn starts the game. In one move, a player can take either the leftmost or the rightmost card. The player always takes the card with the highest number. The game ends when there are no cards left on the table. Print the sum of the numbers on Huseyn's and Yaroslav's cards.
The first line contains the number of cards on the table. The second line contains positive integers written on the cards. All numbers are not greater than .
Print the sum of the numbers on Huseyn's and Yaroslav's cards at the end of the game.