{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+,Y+}
var
  n: longint;
  t, no, d, h: array [1..11000] of longint;

procedure ReadAll;
var i: integer;
begin
{  Assign(Input, 'olymp.in'); Reset(Input);}

  Read(n);
  for i := 1 to n do begin
    Read(t[i]);
    no[i] := i;
  end;

{  Close(Input);}
end;

procedure OutH(k: integer);
begin
  if (k>2) then begin
    if (h[k] = 1) then begin
      OutH(k-1); WriteLn(' ', no[1]:1);
      Write(no[1]:1, ' ', no[k]:1);
    end else begin
      OutH(k-2); WriteLn(' ', no[1]:1);
      WriteLn(no[k-1]:1, ' ', no[k]:1, ' ', no[2]:1);
      Write(no[1]:1, ' ', no[2]:1);
    end;
  end else Write(no[1]:1, ' ', no[2]:1);
end;

procedure Out;
var
  i: integer;
begin
{  Assign(Output, 'olymp.out'); ReWrite(Output);}

  WriteLn(d[n]:1);
{  OutH(n);}
{  WriteLn;}

{  Close(Output);}
end;

procedure Sort(l, r: integer);
var
  i, j, m: integer;
  h: longint;
begin
  i := l; j := r;
  m := t[(i+j) div 2];
  repeat
    while (t[i] < m) and (i<=r) do inc(i);
    while (t[j] > m) and (j>=l) do dec(j);

    if (i<=j) then begin
      h := t[i]; t[i] := t[j]; t[j] := h;
      h := no[i]; no[i] := no[j]; no[j] := h;
      inc(i); dec(j);
    end;
  until (i>j);

  if (i < r) then Sort(i, r);
  if (l < j) then Sort(l, j);
end;

function max(a, b: longint): longint;
begin
  if (a>b) then max := a else max := b;
end;

procedure Solve;
var
  i: integer;
  v: longint;
begin
  Sort(1, n);
  fillchar(d, sizeof(d), 0);
  fillchar(h, sizeof(h), 0);
  d[2] := max(t[1], t[2]);
  for i := 3 to n do begin
    d[i] := d[i-1] + t[1] + t[i]; h[i] := 1;
    if (i>3) then begin
      v := d[i-2] + t[1] + t[i] + t[2] + t[2];
      if (v < d[i]) then begin
        d[i] := v;
        h[i] := 2;
      end;
    end;
  end;
end;

begin
  ReadAll;
  Solve;
  Out;
end.
