cswork / OAOpen practice workspace

AmazonOA #81

Maximum System Memory Capacity (Primary-Backup Pairing)

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

An even number of servers form primary-backup pairs one to one, and in each pair the backup's memory must be ≤ the primary's memory. Maximize the total memory of all primaries; note that the direction of the inequality in this problem follows the statement text.

Input

The first line contains an even n (2..200000), and the second line contains n memory values (1..10⁹).

Output

Output a single integer answer.

Example 1

Input:

4
1 2 3 4

Output:

7

Example 2

Input:

2
8 8

Output:

8

Example 3

Input:

4
2 2 9 10

Output:

19

Example notes

Example 1: 3 and 4 are primaries, paired with 1 and 2, for a total of 7. Example 2: equality is allowed, so the primary memory is 8. Example 3: 9 and 10 are primaries and the two 2s are backups, for a total of 19.

Editorial

Loading solution…