4
#include<stdio.h> #include<string.h> #define N 100015 int d[N][15],a[N][15]; int max(int a,int b) { return a>b?a:b; } int Max(int a,int b,int c) { int t; if(a<b) { t = a; a = b; b = t; } if(a<c) { t = a; a = c; c = t; } return a; } int main() { int n,i,j,maxt,x,t; while(scanf("%d",&n)&&n) { memset(a,0,sizeof(a)); memset(d,0,sizeof(d)); maxt = 0; while(n--) { scanf("%d %d",&x,&t); a[t][x]++; maxt = max(maxt,t); } for(j = 0;j<11;j++) d[maxt][j] = a[maxt][j]; for(i = maxt-1;i>=0;i--) { for(j = 0;j<11;j++) { if(j==0) d[i][j] = a[i][j]+ max(d[i+1][j+1],d[i+1][j]); if(j==10) d[i][j] = a[i][j]+max(d[i+1][j-1],d[i+1][j]); else d[i][j] = a[i][j]+Max(d[i+1][j],d[i+1][j-1],d[i+1][j+1]); } } printf("%d\n",d[0][5]); } return 0; }