program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

var
  a, b :array [1..200000] of int64;
  n, i, j, ma, mb, q :integer;

begin
  reset(input, 'missions.in');
  rewrite(output, 'missions.out');
  readln(n);
  for i := 1 to n do begin
    readln(a[i], b[i]);
  end;
  ma := 1;
  mb := 1;
  for i := 1 to n do begin
    if a[ma] < a[i] then ma := i;
    if b[mb] < b[i] then mb := i;
  end;
  q := 0;
  if (mb = ma) then begin
  	writeln(a[ma] + b[mb]);
  	write(ma, ' ');
  end
  else
  if a[mb] >= b[ma] then begin
    writeln(a[ma] + b[mb] + b[ma]);
    write(ma, ' ', mb, ' ');
  end else begin
    writeln(a[ma] + b[mb] + a[mb]);
    write(mb, ' ', ma, ' ');
  end;
  for i := 1 to n do begin
    if (i <> ma) and (i <> mb) then begin
      write(i, ' ');
    end;
  end;
  readln;
  readln;
end.