Inha Bank has only one ATM. Right now N people are standing in line in front of it. The people are numbered 1 through N, and person i needs Pi minutes to withdraw money.
A person can start only after everyone ahead of them has finished, so the time a person needs to finish withdrawing is the sum of the withdrawal times of everyone ahead plus their own. The total of those finish times therefore depends on the order of the line.
For example, take 5 people with P1=3, P2=1, P3=4, P4=3, P5=2. In the order 1, 2, 3, 4, 5, person 1 takes 3 minutes, person 2 takes 3+1=4 minutes, person 3 takes 3+1+4=8 minutes, person 4 takes 3+1+4+3=11 minutes, and person 5 takes 3+1+4+3+2=13 minutes, for a total of 3+4+8+11+13=39 minutes. In the order 2, 5, 1, 4, 3 the finish times are 1, 3, 6, 9, and 13 minutes, for a total of 32 minutes, and no order gives a smaller total.
Given the number of people N and the withdrawal time Pi of every person, write a program that finds the smallest possible sum of the times the people need to withdraw money.
The first line contains the number of people N (1≤N≤1000).
The second line contains the withdrawal times P1,P2,…,PN, separated by spaces (1≤Pi≤1000).
Print the smallest possible sum of the times the people need to withdraw money on the first line.