{
TASK: SLIDESJ
LANG: PASCAL
}
program slides1;

  const PRF = 'SLIDES.DAT';
        RZF = 'SLIDES.REZ';
        MAX_N = 500;

  type Tmas = array [1..2*MAX_N] of integer;

  var N: integer;
      ilg: Tmas;
      nr:  Tmas;

  procedure Qsort (ind1, ind2: integer);
    var y, i, j, tarp: integer;
  begin
    i := ind1; j := ind2;
    y := ilg[(i+j) div 2];
    repeat
      while y > ilg[i] do i := i + 1;
      while y < ilg[j] do j := j - 1;
      if i <= j
         then begin
                tarp := ilg[i]; ilg[i] := ilg[j]; ilg[j] := tarp;
                tarp := nr[i]; nr[i] := nr[j]; nr[j] := tarp;
                i := i + 1;
                j := j - 1;
              end;
    until i > j;
    if ind1 < j then Qsort (ind1, j);
    if i < ind2 then Qsort (i, ind2);
  end; { Qsort }

  function min_suma: longint;
    var suma, i: longint;
  begin
    suma := 0;
    for i := 1 to N do
      suma := suma + abs (ilg[2*i]-ilg[2*i - 1]);
    min_suma := suma;
  end; { min_suma }

  procedure skaityti (var N: integer; var ilg: Tmas);
    var f: text;
        i: integer;
  begin
    assign (f, PRF);
    reset (f);
    readln (f, N);
    for i := 1 to 2*N do
      begin
        readln (f, ilg[i]);
        nr[i] := i;
      end;
    close (f);
  end; { skaityti }

  procedure rasyti (min_suma: longint);
    var f: text;
        i: integer;
  begin
    assign (f, RZF);
    rewrite (f);
    writeln (f, min_suma);
    for i := 1 to N do
      writeln (f, nr[2*i], ' ', nr[2*i-1]);
    close (f);
  end; { rasyti }

  var suma: longint;
begin
  skaityti (N, ilg);
  Qsort (1, 2*N);
  suma := min_suma;
  rasyti (min_suma);
end.
