Follow the Trace!
InterviewTime limit1sMemory limit512 MB
Given n integers, build a nonempty square matrix using each value at most as many times as it appears, and maximize the diagonal sum.
Problem
The trace of a square matrix is the sum of the elements on the main diagonal.
You are given a sequence of integers . You must place the numbers of the sequence into a non-empty square matrix so that its trace is as large as possible. If a number occurs exactly times in the sequence , then it must occur at most times in the matrix .
Input
The first line contains a single integer , the length of the sequence ().
The next lines each contain a single integer; the -th of them contains , the -th element of the sequence ().
Output
Print a single integer: the largest possible value of the trace of the matrix .