Program Ferry;
  Type mas=array[1..10000] of longint;
  Var n,i,r,r1,r2:longint;
                a:mas;
 Procedure Qsort(u,d:longint);
   Var k,m,x,t,kor:longint;
 Begin
   t:=u;
   k:=u-1;
   m:=d+1;
   x:=a[u+(d-u) div 2];
   while t<m do
     begin
       if a[t]<x then
         begin
           k:=k+1;
           kor:=a[t];
           a[t]:=a[k];
           a[k]:=kor;
           t:=t+1;
         end
        else
         begin
           if a[t]>x then
             begin
               m:=m-1;
               kor:=a[t];
               a[t]:=a[m];
               a[m]:=kor;
             end
            else t:=t+1;
         end;
     end;
   if k>u then qsort(u,k);
   if m<d then qsort(m,d);
 End;
Begin
  read(n);
  for i:=1 to n do read(a[i]);
  qsort(1,n);
  i:=n;
  r:=0;
  while i>3 do
    begin
      r1:=a[i]+2*a[2]+a[1];
      r2:=a[i]+a[i-1]+2*a[1];
      i:=i-2;
      if r1<r2 then r:=r+r1
               else r:=r+r2;
    end;
  if i=3 then r:=r+a[1]+a[2]+a[3]
         else r:=r+a[2];
  writeln(r);
End.
