cswork / OAOpen practice workspace

OracleOA #11

Array Reduction 1

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsGreedy

Each time, choose two elements at different positions, pay their sum, and replace the two elements with that sum. Continue until only one element remains, and find the minimum total cost.

Input

The first line contains n, and the second line contains n integers. Full original bounds: 2≤n≤10000, 0≤a[i]≤100000. The answer may exceed the range of a 32-bit integer.

Output

Output a single integer, the answer.

Example 1

Input:

3
4 6 8

Output:

28

Example 2

Input:

3
1 2 3

Output:

9

Example 3

Input:

3
0 0 9

Output:

9

Example notes

The outputs of the three public examples are, in order: 28; 9; 9. They were verified by independent enumeration or direct simulation.

Editorial

Loading solution…