program cch(input,output,f1,f2);
var
f1,f2:text;
a:array[1..20000] of longint;
i,j,n:longint;
s,x:int64;
procedure qsort(l,r:integer);
var
i,j,temp:integer;
begin
i:=l; j:=r;
x:=a[l];
repeat
while a[j]>x do dec(j);
while a[i]<x do inc(i);
if i<=j then begin
temp:=a[j]; a[j]:=a[i]; a[i]:=temp;
inc(i); dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
begin
assign(f1,'fruit.in');
assign(f2,'fruit.out');
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do read(f1,a[i]);
qsort(1,n);
x:=a[1]+a[2]; s:=x;
for i:=3 to n do begin
a[i-1]:=x;
qsort(i-1,n);
x:=a[i-1]+a[i];
s:=s+x;
end;
writeln(f2,s);
close(f1);
close(f2);
end.