program fruit;
var
a:array[0..1000000]of longint;
n,t:longint;
f1,f2:text;
procedure insert(x:longint);
var
s,h:longint;
begin
inc(t);
a[t]:=x;
s:=t;
while (s>1)and(a[s]<a[s div 2])do begin
h:=a[s];a[s]:=a[s div 2];a[s div 2]:=h;
s:=s div 2;
end;
end;
procedure del;
var
s,j,h:longint;
begin
a[1]:=a[t];
dec(t);
s:=1;
while (s*2<=t) do begin
if (s*2=t)or(a[s*2]<a[s*2+1])then j:=s*2
else j:=s*2+1;
if a[s]>a[j] then begin
h:=a[s];a[s]:=a[j];a[j]:=h;
s:=j;
end
else exit;
end;
end;
procedure ini;
var
i,x:longint;
begin
assign(f1,'fruit.in');reset(f1);
assign(f2,'fruit.out');rewrite(f2);
read(f1,n);
t:=0;
for i:=1 to n do begin
read(f1,x);
insert(x);
end;
end;
procedure main;
var
i,x:longint;
ans:longint;
begin
ini;
ans:=0;
for i:=1 to n-1 do begin
x:=a[1];
del;
inc(x,a[1]);
del;
inc(ans,x);
insert(x);
end;
write(f2,ans);
end;
begin
main;
close(f1);
close(f2);
end.