#include #include // require memset #include // require sort next_permutation count __gcd reverse etc. #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; bool is_win(int n, int k){ return (n - 1) % (k + 1) != 0; // 先攻が勝つ true 後攻が勝つ false } int n[1000], k[1000]; bool game[1000]; // 先攻が勝利する true 敗退する false bool res[1000]; int main() { memset (n, 0, sizeof(n)); memset (k, 0, sizeof(k)); memset (game, false, sizeof(game)); memset (res, false, sizeof(res)); ios_base::sync_with_stdio(0); rep (i, 1000){ cin >> n[i] >> k[i]; game[i] = is_win(n[i],k[i]); } // end rep bool batting_first = true; res[0] = game[0]; for (int i = 1; i < 1000; ++i){ if (!res[i-1]){ batting_first = game[i]; }else{ batting_first = !game[i]; } // end if res[i] = !(batting_first ^ game[i]); } // end for int ans = count(res, res+1000, true); cout << ans << endl; return 0; }