program fruit(input,output);
var
a:array[1..10000]of longint;
s:longint;
p,q,n:longint;
procedure qsort(l,r:integer);
var x,i,j,t:integer;
begin
i:=l;j:=r;x:=a[i];
repeat
while(i<j)and(a[j]>=x)do dec(j);
t:=a[i];a[i]:=a[j];a[j]:=t;
while(i<j)and(a[i]<=x)do inc(i);
t:=a[j];a[j]:=a[i];a[i]:=t;
until i=j;
i:=i+1;j:=j-1;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
procedure ins(num:longint);
var i,j,m:longint;
begin
if num<=a[p+2]then a[p+1]:=num;
if num>=a[n]then begin
for i:=p+1 to n-1 do a[i]:=a[i+1];
a[n]:=num;
end;
if(num>a[p+2])and(num<a[n])then begin
i:=p+2; j:=n;
while j<>i+1 do begin
m:=(i+j)div 2;
if a[m]<=num then i:=m;
if a[m]>num then j:=m;
end;
for j:=p+1 to i-1 do a[j]:=a[j+1];
a[i]:=num;
end;
end;
begin
assign(input,'fruit.in');assign(output,'fruit.out');
reset(input);rewrite(output);
readln(n);
s:=0;
for p:=1 to n do read(a[p]);
if n=1 then s:=a[1];
if n>1 then begin
qsort(1,n);
for p:=1 to n-2 do begin
q:=a[p]+a[p+1];
s:=s+q;
ins(q);
end;
q:=a[p+1]+a[p+2];
s:=s+q;
end;
write(s);
close(input);close(output);
end.