{$Q-,R-,I-,O+}

uses SysUtils,Math;  

{type cardinal = longword; }

const FileName = 'cycles';
      MaxN = 2500;
      MaxV = 2500;


var i,n:integer;
    d,l,r:array[0..MaxN] of integer;
    hh:array[0..MaxN,0..MaxV] of cardinal;
    e:array[0..MaxN,0..MaxV] of integer;
    s:cardinal;
    gone:array[0..MaxN] of boolean;



function poisk(v,k:integer):cardinal;
var i,j:integer;
    ss:cardinal;
begin
  if not gone[v] then begin
    for i:=0 to r[v] do begin
      ss:=1;
      for j:=1 to d[v] do begin
        if not gone[e[v][j]] then
          ss:=ss*poisk(e[v][j],i)
        else
          ss:=ss*hh[e[v][j],i];
      end;
      hh[v][i]:=ss;
    end;
    for i:=r[V]-1 downto 0 do
      hh[v,i]:=hh[v,i]+hh[v,i+1];
    for i:=r[v]+1 to MaxV do hh[v][i]:=0;
  end;
  {assert(not gone[v]);}
  gone[v]:=true;
  poisk:=hh[v][k];
end;
      

begin
  reset(input,FileName+'.in');
  rewrite(output,FileName+'.out');
//  while not seekeof do begin
    read(n);
    assert(n<=MaxN);
    for i:=1 to n do begin
      read(l[i],r[i]);
//      writeln (l[i], ' ',r[i]);
      assert(-l[i]<i);
      assert(l[i]<=maxV);
      assert(r[i]>=0);
      assert(r[i]<=maxV);
    end;
    assert(seekeof);
    fillchar(d,sizeof(d),0);
    for i:=1 to n do
      if l[i]<0 then begin
        inc(d[-l[i]]);
        e[-l[i]][d[-l[i]]]:=i;
      end;
    s:=1;
    fillchar(gone,sizeof(gone),0);
    for i:=1 to n do
      if not gone[i] then begin
        s:=s*poisk(i,l[i]);
      end;
    writeln (s);  
//  end; 
end.


