#P6377. [PA 2010] Termites

[PA 2010] Termites

Description

There is a sequence aa of length nn. Two players take turns. Each time, a player may choose a number that is adjacent to 00, gain a score equal to its value, and change it to 00. Find the scores of the two players if both play optimally.

Input Format

The first line contains an integer nn, as described in the statement.

The next line contains nn integers, representing the sequence.

Output Format

Output one line with two integers, representing the final scores of the two players when both play optimally.

8
1 2 0 3 7 4 0 9

17 9

Hint

Constraints

For all testdata, it is guaranteed that 1n1061\leq n\leq 10^6. For any element xx in aa, it is guaranteed that 0x1060\leq x\leq 10^6, and there is at least one 00.

Translated by ChatGPT 5