import java.util.PriorityQueue ;
import java.util.Scanner ;
public class Main {
public static void main
( String [ ] args
) { PriorityQueue< Long> nums = new PriorityQueue< Long> ( ) ;
Scanner sc
= new Scanner
( System .
in ) ; long n = sc.nextLong ( ) ;
for ( int i = 0 ; i < n; i++ ) {
long number = sc.nextLong ( ) ;
nums.add ( number) ;
}
long minSum = 0 ;
long a;
long b;
while ( ! nums.isEmpty ( ) ) {
a = nums.poll ( ) ;
if ( nums.isEmpty ( ) ) {
break ;
}
b = nums.poll ( ) ;
minSum += a + b;
nums.add ( a + b) ;
}
}
}
aW1wb3J0IGphdmEudXRpbC5Qcmlvcml0eVF1ZXVlOwppbXBvcnQgamF2YS51dGlsLlNjYW5uZXI7CgpwdWJsaWMgY2xhc3MgTWFpbiB7CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFByaW9yaXR5UXVldWU8TG9uZz4gbnVtcyA9IG5ldyBQcmlvcml0eVF1ZXVlPExvbmc+KCk7CiAgICAgICAgU2Nhbm5lciBzYyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICAgbG9uZyBuID0gc2MubmV4dExvbmcoKTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgICBsb25nIG51bWJlciA9IHNjLm5leHRMb25nKCk7CiAgICAgICAgICAgIG51bXMuYWRkKG51bWJlcik7CiAgICAgICAgfQoKICAgICAgICBsb25nIG1pblN1bSA9IDA7CiAgICAgICAgbG9uZyBhOwogICAgICAgIGxvbmcgYjsKICAgICAgICB3aGlsZSAoIW51bXMuaXNFbXB0eSgpKSB7CiAgICAgICAgICAgIAogICAgICAgICAgICBhID0gbnVtcy5wb2xsKCk7CiAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICBpZiAobnVtcy5pc0VtcHR5KCkpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGIgPSBudW1zLnBvbGwoKTsKICAgICAgICAgICAgbWluU3VtICs9IGEgKyBiOyAgICAgICAgICAgIAogICAgICAgICAgICBudW1zLmFkZChhICsgYik7CgogICAgICAgIH0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4obWluU3VtKTsKCiAgICB9Cn0K