~/algor $ cat problems/ochkoz-navbatda-kutish
Waiting time in a queue
Easy
1000 ms
128 MB
20%
$n$ customers have come to a single checkout; serving the $i$-th customer takes $t_{i}$ minutes. The cashier may serve the customers in any order. Each customer waits until everyone before them has been served (the first one waits $0$ minutes). Choose the order that minimizes the total waiting time of all customers and find this total.
Input
The first line contains a positive integer $n$. The second line contains $n$ space-separated positive integers $t_{i}$.
Output
One integer — the minimum total waiting time.
Note
$1 \le n \le 10^{5}$
$1 \le t_{i} \le 10^{9}$
Examples
Input #1
3 5 1 3
Output #1
5
Input #2
4 2 2 2 2
Output #2
12