Score : 100 points
Taro and Jiro will play the following game against each other.
Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N). Until a becomes empty, the two players perform the following operation alternately, starting from Taro:
Let X and Y be Taro's and Jiro's total score at the end of the game, respectively. Taro tries to maximize X - Y, while Jiro tries to minimize X - Y.
Assuming that the two players play optimally, find the resulting value of X - Y.
Input is given from Standard Input in the following format:
N a_1 a_2 \ldots a_N
Print the resulting value of X - Y, assuming that the two players play optimally.
4 10 80 90 30
10
The game proceeds as follows when the two players play optimally (the element being removed is written bold):
Here, X = 30 + 80 = 110 and Y = 90 + 10 = 100.
3 10 100 10
-80
The game proceeds, for example, as follows when the two players play optimally:
Here, X = 10 + 10 = 20 and Y = 100.
1 10
10
10 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1
4999999995
The answer may not fit into a 32-bit integer type.
6 4 2 9 7 1 5
2
The game proceeds, for example, as follows when the two players play optimally:
Here, X = 5 + 1 + 9 = 15 and Y = 4 + 7 + 2 = 13.