#include using namespace std; typedef long long ll; const ll mod=1e9+7; ll n,t,x,dp[3005][3005],cnt; vector V[2]; int main(){ cin >> n,dp[0][0]=1; for(int i=1;i<=n;i++) cin >> t >> x,V[t].push_back(x-1),cnt+=(t==0); sort(V[0].begin(),V[0].end()),sort(V[1].begin(),V[1].end()); for(int i=0;i