//2013-05-17-21.08 #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int maxn = 100004; int dp[maxn][12]; int main() { int n, maxt, t, x; int tmax; while(scanf("%d", &n) && n) { memset(dp, 0, sizeof(dp)); maxt = 0; for (int i = 0; i < n; i++) { scanf("%d%d",&x, &t); maxt = max(t, maxt); dp[t][x]++; } t = maxt; for (t--; t >= 0; t--) { for (int i = 0; i <= 10; i++) { if (i == 0) tmax = max(dp[t+1][i], dp[t+1][i+1]); else if (i == 10) tmax = max(dp[t+1][i], dp[t+1][i-1]); else { tmax = max(dp[t+1][i-1], dp[t+1][i]); tmax = max(tmax, dp[t+1][i+1]); } dp[t][i] += tmax; } } printf("%d\n", dp[0][5]); } return 0; }