program pr_j;

{$APPTYPE CONSOLE}


var
  a,b,c,d,dd,cc,e,ee:array[0..1010]of longint;


Procedure Merge(p,q,r:Longint);
 Var I,J,K:Longint;
Begin
  I:=p;
  J:=q+1;
  For K:=p To r Do
   If (I>q) Or ((J<=r) And (d[J]<d[I])) Then
    Begin
      dd[K]:=d[J];
      cc[K]:=c[J];
      ee[K]:=e[J];
      Inc(J);
    End
   Else
    Begin
      dd[K]:=d[I];
      cc[K]:=c[I];
      ee[K]:=e[I];
      Inc(I);
    End;
  For K:=p To r Do begin
   d[K]:=dd[K];
   c[K]:=cc[K];
   e[K]:=ee[K];
  end;
End;

Procedure Sort(p,r:Longint);
 Var q:Longint;
Begin
  If p<r Then
   Begin
     q:=(p+r) SHR 1;
     Sort(p,q);
     Sort(q+1,r);
     Merge(p,q,r);
   End;
End;

var
  m,i,j,k,n,l:longint;
  din:array[-1..1010]of longint;
  tmpdin:array[-1..1010]of longint;
  tmplastc,lastc:array[0..1010]of longint;
  glastc:array[0..1010]of longint;
  tmplastcs,lastcs:array[0..1010,0..1010]of longint;

begin
  assign(input,'joke.in');reset(input);
  assign(output,'joke.out');rewrite(output);

  read(n);
  k:=0;
  for i:=1 to n do begin
    read(a[i],b[i]);
    if a[i]+b[i]<n then begin
      inc(k);
      c[k]:=a[i];
      d[k]:=n-b[i];
      e[k]:=i;
    end;
  end;
  sort(1,k);
  fillchar(din,sizeof(din),0);
  j:=1;
  for i:=1 to n do begin
    fillchar(tmpdin,sizeof(tmpdin),0);
{    fillchar(tmplastc,sizeof(tmplastc),0);
    fillchar(tmplastcs,sizeof(tmplastcs),0);}
    while (j<=k)and(d[j]<i) do begin j:=j+1; end;
    while (j<=k)and(d[j]=i) do begin
      if tmpdin[d[j]-c[j]]<(d[j]-c[j]) then begin
        inc(tmpdin[d[j]-c[j]]);
{        inc(tmplastc[d[j]-c[j]]);}
        tmplastcs[d[j]-c[j],tmpdin[d[j]-c[j]]]:=e[j];
      end;
      inc(j);
    end;
    din[i]:=din[i-1];m:=0;
    for l:=1 to i do begin
      if (tmpdin[l]>0) and (din[i-l]+tmpdin[l]>din[i]) then begin
        din[i]:=din[i-l]+tmpdin[l];
        m:=l;
      end;
    end;
    lastc[i]:=tmpdin[m];
    glastc[i]:=m;
    if glastc[i]=0 then glastc[i]:=1;
    for l:=1 to lastc[i] do
      lastcs[i,l]:=tmplastcs[m,l];
  end;
  fillchar(tmpdin,sizeof(tmpdin),0);
  i:=n;
  while i>0 do begin
    for j:=1 to lastc[i] do
      tmpdin[lastcs[i,j]]:=1;
    i:=i-glastc[i];
  end;
  l:=0;
  for i:=1 to n do if tmpdin[i]=0 then inc(l);
  write(l);
  for i:=1 to n do if tmpdin[i]=0 then write(' ',i);
  close(input);
  close(output);
end.
