LearnPy Hub
← Arena
EasyRating 900

Cards from Both Ends

Cards with distinct numbers lie in a row. Two players take turns, the first player starting. On each turn a player takes the larger of the two end cards. Print both players' totals.

Input

n, then n distinct integers.

Output

Two integers.

Sample 1

Input
4
4 1 2 10
Output
12 5

Sample 2

Input
7
1 2 3 4 5 6 7
Output
16 12
solution.py
Output appears here
Cards from Both Ends · Python Arena problem · LearnPy Hub