{$D+,I-,L-,R-}
var
  a:array[1..10000]of word;
  num:array[1..10000]of word;
  para:array[1..10000]of record x,y,z:word;end;
  n,i:word;
  min:longint;
procedure init;
var i:integer;
begin
  assign(input,'');
  reset(input);
  read(n);
  for i:=1 to n do
    begin
      read(a[i]);
      num[i]:=i;
    end;
  close(input);
end;
procedure Sort(l, r: Integer);
var
  i, j, x, y: integer;
begin
  i := l; j := r; x := a[(l+r) DIV 2];
  repeat
    while a[i] < x do i := i + 1;
    while x < a[j] do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y;
      y := num[i]; num[i] := num[j]; num[j] := y;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);
end;
procedure work;
var m:word;
begin
  m:=n;
  i:=0;
  while m>2 do
    if a[2]+a[2]+a[m]>a[m]+a[1]+a[m-1] then
      begin
        min:=min+a[m]+a[1]+a[m-1];
        inc(i);
        para[i].x:=num[1];
        para[i].y:=num[m];
        para[i].z:=num[1];
        inc(i);
        para[i].x:=num[1];
        para[i].y:=num[m-1];
        para[i].z:=num[1];
        dec(m,2);
        if m>1 then begin
           {writeln(num[1]);} min:=min+a[1];
           end;
      end
    else
      begin
        min:=min+a[2]+a[2]+a[m];
        inc(i);
        para[i].x:=num[1];
        para[i].y:=num[2];
        para[i].z:=num[2];
        inc(i);
        para[i].x:=num[m];
        para[i].y:=num[m-1];
        para[i].z:=num[1];
        dec(m,2);
        if m>1 then begin
           {writeln(num[1])};min:=min+a[1];
           end;
      end;
  if m=2 then
    begin
     inc(i);
     para[i].x:=num[1];
     para[i].y:=num[2];
     min:=min+a[2];
    end;
end;
procedure out;
var j:word;
begin
  assign(output,'');
  rewrite(output);
  writeln(min);
  for j:=1 to i do
    if i<>j then {writeln(para[j].x,' ',para[j].y,' ',para[j].z)}
    else {writeln(para[j].x,' ',para[j].y);
  close(output);                           }
end;
begin
  init;
  sort(1,n);
  work;
  out;
end.
