#C6063. Minimum Effort to Cut Trees

    ID: 49782 Type: Default 1000ms 256MiB

Minimum Effort to Cut Trees

Minimum Effort to Cut Trees

Problem Statement: Given a list of tree heights, your task is to determine the minimum total effort required to ensure that no tree height appears more than once.

For each extra occurrence of a particular tree height (i.e. a duplicate), you must "cut" the tree. The cost to cut a tree is equal to its height. Thus, for any height that appears more than once, the extra copies (beyond the first occurrence) contribute to the overall effort by (frequency - 1) * height.

Example: Consider the list [1, 2, 2, 3, 4, 4]. Here, the height 2 occurs twice (adding a cost of 2) and the height 4 occurs twice (adding a cost of 4). Therefore, the total minimum effort is 2 + 4 = 6.

Your goal is to compute and output this total effort.

inputFormat

The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of trees.

The second line contains n space-separated integers, where each integer denotes the height of a tree.

outputFormat

Output a single integer, which is the minimum total effort required to ensure that no tree height is repeated more than once.

## sample
6
1 2 2 3 4 4
6

</p>