var
heap:array[1..20000]of int64;
htop,n,i:longint;
ans,tp:int64;
procedure push(x:int64);
var
p,fa:longint;
begin
inc(htop);p:=htop;
while p>1 do
begin
fa:=p div 2;
if heap[fa]<=x then break;
heap[p]:=heap[fa];p:=fa;
end;
heap[p]:=x;
end;
procedure pop;
var
fa,son,x:longint;
begin
x:=heap[htop];dec(htop);fa:=1;
while fa<=htop do
begin
son:=fa*2;
if son>htop then break;
if (son+1<=htop)and(heap[son]>heap[son+1]) then inc(son);
if heap[son]>=x then break;
heap[fa]:=heap[son];fa:=son;
end;
heap[fa]:=x;
end;
begin
assign(input,'fruit.in');
reset(input);
assign(output,'fruit.out');
rewrite(output);
read(n);
for i:=1 to n do
begin
read(tp);
push(tp);
end;
for i:=1 to n-1 do
begin
tp:=heap[1];
pop;
inc(tp,heap[1]);
pop;
push(tp);
inc(ans,tp);
end;
writeln(ans);
close(input);
close(output);
end.