#include #include #include using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 vector N(1000),K(1000); int dp[1001][2]; bool f[1001][2]; int get(int turn,int player){ if(turn==1000)return 0; if(f[turn][player])return dp[turn][player]; f[turn][player] = true; int r = N[turn] % K[turn]; int ret = -Inf; if(r==0){ ret = get(turn+1,player); } else if(r==1){ ret = -get(turn+1,player^1) + 1; } else{ ret = max(get(turn+1,player), -get(turn+1,player^1)+1); } dp[turn][player] = ret; return ret; } int main(){ rep(i,1000)cin>>N[i]>>K[i]; int ans = get(0,0); rep(i,1001){ if(i-(1000-i)==ans){ cout<