~/algor $ cat problems/ochkoz-arqonlarni-ulash
Joining ropes
Medium
1000 ms
128 MB
51%
There are $n$ ropes, the length of the $i$-th one is $a_{i}$. In one operation any two ropes are joined; joining ropes of lengths $x$ and $y$ costs $x + y$ soums and produces one rope of length $x + y$. What is the smallest amount of money needed to join all the ropes into one?
Input
The first line contains a positive integer $n$. The second line contains $n$ space-separated positive integers $a_{i}$.
Output
One integer — the smallest total cost.
Note
$1 \le n \le 10^{5}$
$1 \le a_{i} \le 10^{9}$
Examples
Input #1
4 4 3 2 6
Output #1
29
Input #2
1 10
Output #2
0