401524: GYM100488 K Two Pirates

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Two Piratestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

The famous pirate Jack Sparrow and not so famous pirate Ferrante Albrizzi, even less known as Malasorte, have robbed a Spanish trading schooner together and decided to divide the loot. The loot consists of n numbered items, the i-th of which costs ai piastres.

The pirates decided to take items in rotation. Jack Sparrow takes first because he is more famous. But Ferrante Albrizzi is not interested in money since he has become a pirate not because of them, so he just always takes the first item that hasn't been taken yet. Jack Sparrow perfectly knows it and wants to act to maximize the cost of his part of the loot. Determine how much piastres their loot will cost.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of items in the loot.

The second line contains n integers separated by spaces: ai (1 ≤ ai ≤ 109) — the cost of the i-th item.

Output

Output in the only line two integers separated by a space: the cost of loot taken by Jack Sparrow and the cost of loot taken by Ferrante Albrizzi.

ExamplesInput
5
3 1 2 4 1
Output
8 3
Input
6
8 5 3 6 1 4
Output
18 9

加入题单

上一题 下一题 算法标签: