Bark Beetles

No attempts yetTime limit1sMemory limit128 MB

Problem

Two bark beetles have decided to devour an old wooden fence. The fence is a row of nn pickets whose heights are not necessarily equal. To make the meal more fun, the beetles turned it into a game and eat the pickets in alternating turns.

On its turn a beetle may either eat one of the two pickets currently at an end of the fence (the leftmost or the rightmost), or eat both end pickets at once. Each beetle always chooses so that the total height of the pickets it eats over the whole game is as large as possible.

The first beetle moves first. Determine how much wood each beetle ends up eating.

Input

The first line contains an integer nn (1n1061 \le n \le 10^6), the number of pickets.

The second line contains nn integers h1,h2,,hnh_1, h_2, \dots, h_n (1hi1091 \le h_i \le 10^9), the heights of the pickets from left to right.

Output

Print two integers on a single line: first the total height of the pickets eaten by the beetle that starts the game, then the total height eaten by its opponent.

Note

Consider the fence 5 2 9 35\ 2\ 9\ 3. On the first turn the starting beetle can take the picket of height 55, the picket of height 33, or both ends at once. Eating the picket of height 55 is optimal: the opponent then faces 2 9 32\ 9\ 3 and eats both ends (22 and 33) at once, leaving 99 for the starter. The starter eats 5+9=145+9=14 and the opponent eats 2+3=52+3=5.