cswork / OAOpen practice workspace

AmazonOA #6

Get Score Difference

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

Two players take turns picking any positive integer from the remaining array, adding it to their own score and removing it. Player 1 moves first, and play continues until the array is empty. Both players want to maximize their own final score; find the absolute difference between the two scores under optimal play.

Input

The first line contains n (1..100000), and the second line contains n values (1..10⁹).

Output

Output a single integer, the answer required by the problem.

Example 1

Input:

4
4 1 2 3

Output:

2

Example 2

Input:

1
9

Output:

9

Example 3

Input:

3
1 1 1

Output:

1

Example notes

In example 1, 4, 3, 2, 1 are taken in order; player 1 gets 6 and player 2 gets 4, so the difference is 2.

Editorial

Loading solution…