Under construction

Still being built. Things may change

Follow the Trace!

Interview

Time limit1sMemory limit512 MB

Summary
Given n integers, build a nonempty square matrix using each value at most as many times as it appears, and maximize the diagonal sum.
Level

Easy3 of 10

Topics
Greedy, Sorting, Math, Array
Solved
No attempts yet

Problem

The trace of a square matrix BijB_{ij} is the sum of the elements BiiB_{ii} on the main diagonal.

You are given a sequence of integers aia_i. You must place the numbers of the sequence into a non-empty square matrix BijB_{ij} so that its trace is as large as possible. If a number xx occurs exactly kk times in the sequence aia_i, then it must occur at most kk times in the matrix BijB_{ij}.

Input

The first line contains a single integer nn, the length of the sequence aia_i (1≤n≤1051 \le n \le 10^5).

The next nn lines each contain a single integer; the ii-th of them contains aia_i, the ii-th element of the sequence aa (−109≤ai≤109-10^9 \le a_i \le 10^9).

Output

Print a single integer: the largest possible value of the trace of the matrix BB.

Examples1

  1. Example 1

    Input
    6
    31
    10
    2021
    -11
    0
    0
    
    Expected output
    2052