Time limit: 1s
Memory limit: 256MB
Input:
Output:
Task
We define the function (where is an array and is the number of elements of ) as follows:
.
For example: .
You are given and an array . Rearrange the elements of the array in such a way that is maximized.
Input data
The first line of input contains a single integer () - the length of array .
The second line contains space separated integers () - the elements of array .
Output data
Print a single number, representing the maximum possible value of after optimally rearranging the elements of .
Example 1
stdin
4
5 9 10 2
stdout
12
Explanation
One of the optimal rearrangements of is , as .
Example 2
stdin
5
3 2 1 4 5
stdout
9
Explanation
One of the optimal rearrangements of is , as .