Program Drugoy;
  Type mas=array[1..100000] of longint;
  Var n,i,r: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);
  r:=0;
  i:=n;
  while i>3 do
    begin
      r:=r+a[2]+a[1]+a[i]+a[2];
      i:=i-2;
    end;
  if i=3 then r:=r+a[3]+a[2]+a[1]
         else r:=r+a[2];
  rewrite(output);
  writeln(r);
End.
