LearnPy Hub
← Arena
IntermediateRating 1200

Join the Ropes Cheaply

Joining two ropes of lengths x and y costs x + y and gives one rope of length x + y. Print the least total cost to join all ropes into one.

Input

n, then n lengths.

Output

One integer.

Sample 1

Input
4
4 3 2 6
Output
29

Sample 2

Input
1
10
Output
0
solution.py
Output appears here
Join the Ropes Cheaply · Python Arena problem · LearnPy Hub