{$APPTYPE CONSOLE}
{$O-,Q+,R+}

uses Math, SysUtils;

type
  int = integer;
  bool = boolean;
  real = extended;

var
  a, b, c, d, q: array[1..1000] of integer;
  dead, alive: array[1..1000] of boolean;
  z: array[1..1000] of boolean;
  nx: array[1..1000] of integer;
  n: integer;

procedure calc(i: integer);
var
  j, dd, qq: integer;
begin
  if z[i] then exit;
  d[i] := a[i] + q[i];
  nx[i] := 0;
  for j := 1 to n do if not dead[i] then begin
    qq := b[j] - b[i] - c[i];
    if qq < 0 then continue;
    if (b[j] = b[i] + c[i] + qq) and (a[i] = a[j] + c[j] + qq) then begin
      calc(j);
      dd := d[j] + q[i] + qq;
      if dd < d[i] then begin
        d[i] := dd;
        nx[i] := j;
      end;
    end;
  end;
  z[i] := true;
end;

procedure mark(x: integer);
var
  i, j: integer;
begin
  alive[x] := true;
  j := 0;
  for i := 1 to n do if (j < c[x] - q[x]) and (a[i] = a[x]) and (b[i] = b[x]) then begin
    inc(j);
    alive[i] := true;
  end;
  if nx[x] > 0 then mark(nx[x]);
end;

var
  i, j, best, besti: integer;

begin
                     {
  rewrite(output, 'joke.in');
  writeln(1000);
  for i := 1 to 1000 do writeln(random(1000),' ',random(1000));
  exit;
                    }

  reset(input, 'joke.in');
  rewrite(output, 'joke.out');
  read(n);
  for i := 1 to n do read(a[i], b[i]);
  for i := 1 to n do c[i] := n - a[i] - b[i];
  for i := 1 to n do if c[i] <= 0 then dead[i] := true;
  for i := 1 to n do
    for j := 1 to n do if (a[i] = a[j]) and (b[i] = b[j]) then inc(q[i]);
  for i := 1 to n do if q[i] > c[i] then q[i] := 0 else q[i] := c[i] - q[i];

  for i := 1 to n do if not dead[i] then calc(i);
  best := n;
  for i := 1 to n do if not dead[i] then begin
    if d[i] + b[i] < best then begin
      best := d[i] + b[i];
      besti := i;
    end;
  end;
  if best = n then begin
    writeln(n);
    for i := 1 to n do write(i, ' ');
  end else begin
    writeln(best);
    mark(besti);
    for i := 1 to n do if dead[i] or not alive[i] then write(i,' ');
  end;
end.
