program cch(input,output);
var
a:array[1..10000] of longint;
i,n,tot,x,y,ans:longint;
procedure swap(var x,y:longint);
var
t:longint;
begin
t:=x;
x:=y;
y:=t;
end;
procedure ins(x:longint);
var
i:longint;
begin
inc(tot);
a[tot]:=x;
i:=tot;
while (i>1)and(a[i div 2]>a[i]) do
begin
swap(a[i],a[i div 2]);
i:=i div 2;
end;
end;
procedure del;
var
s,j:longint;
begin
a[1]:=a[tot];
dec(tot);
s:=1;
while s*2<=tot do
begin
if (s*2=tot)or(a[s*2]<a[s*2+1]) then j:=s*2
else j:=s*2+1;
if a[s]>a[j] then
begin
swap(a[s],a[j]);
s:=j;
end
else exit;
end;
end;
begin
assign(input,'fruit.in');
assign(output,'fruit.out');
reset(input);
rewrite(output);
readln(n);
tot:=0;
for i:=1 to n do
begin
read(x);
ins(x);
end;
ans:=0;
for i:=1 to n-1 do
begin
x:=a[1];
del;
y:=a[1];
del;
ins(x+y);
ans:=ans+x+y;
end;
write(ans);
close(input); close(output);
end.