var t1,t2,n,sum,i:longint;
a:array[1..1000]of longint;
procedure qsort(l,r:longint);
var t,i,j,mid:longint;
begin
i:=l; j:=r;
mid:=a[(l+r)div 2];
while i<j do
begin
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
inc(i);dec(j);
end;
end;
if l<j then qsort(l,j);
if r>i then qsort(i,r);
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
qsort(1,n);
// for i:=1 to n do write(a[i],' ');
if n mod 2=1 then sum:=a[1]+a[2]+a[3]
else sum:=a[2];
// for i:=n downto 3 do begin
i:=n;
while i>3 do begin
t1:=a[2]+a[1]+a[i]+a[2];
t2:=a[i]+a[1]+a[i-1]+a[1];
if t1>t2 then t1:=t2;
sum:=sum+t1;
i:=i-2;
end;
// end;
writeln(sum);
close(input);
close(output);
end.