Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ochkoz-navbatda-kutish

Waiting time in a queue

Easy 1000 ms 128 MB 20%
Share

$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.

Diagram of the total waiting time of customers in the checkout queue

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

Sign in to submit a solution

Signing up is free and takes a minute.