- Time limit: 1.00 s
- Memory limit: 512 MB
Maija is yet again playing with nuclear physics. This time she has particles spinning in an accelerator and she wants to combine them into one massive particle. Particle has mass . In one operation, Maija can pick 2 of the particles that are spinning in the accelerator and collide them. If the masses of the particles were and , the operation costs energy and creates a particle with mass . Find the most energy efficient way to combine the particles.
Input
The first line contains a single integer : The number of particles.
The second line contains integers : the masses of the particles.
Output
Print one integer: the minimum cost to combine the particles to one.
Constraints
Example 1
Input:
6 3 1 9 9 3 4
Output:
322
Explanation:
one valid sequence of collisions is:
1 2 3 4 5 6
12 3 4 5 6 -> cost
12 3 5 46 -> cost
12 5 346 -> cost
125 346 -> cost
125346 -> cost
Example 2
Input:
10 123 543 234 639 123 2 432 33 224 988
Output:
4580030