cswork / OAOpen practice workspace

Pure StorageOA #3

Two-Player Optimal Pick Difference

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

You are given an integer array. Two players take turns picking any one of the remaining elements; both maximize the sum of their own scores, and the first player moves first. Output the first player's total minus the second player's total under optimal play.

Input

The first line contains n; the second line contains n integers. Ranges added by this site: 1≤n≤200000, |points[i]|≤10^9.

Output

Output score1−score2.

Example 1

Input:

4
4 1 2 3

Output:

2

Example 2

Input:

1
10

Output:

10

Example 3

Input:

3
-5 7 -2

Output:

4

Editorial

Loading solution…