Problem:
Playing with Stones
Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows:
Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in each of the areas.
Koshiro and Ukiko alternately select an area and perform one of the following operations.
(a) Remove a white stone from the area
(b) Remove one or more black stones from the area. Note, however, that the number of the black stones must be less than or equal to white ones in the area.
(c) Pick up a white stone from the stone pod and replace it with a black stone. There are plenty of white stones in the pod so that there will be no shortage during the game.
If either Koshiro or Ukiko cannot perform 2 anymore, he/she loses.
They played the game several times, with Koshiro’s first move and Ukiko’s second move, and felt the winner was determined at the onset of the game. So, they tried to calculate the winner assuming both players take optimum actions.
Given the initial allocation of black and white stones in each area, make a program to determine which will win assuming both players take optimum actions.
Input
The input is given in the following format.
$N$
$w_1$ $b_1$
$w_2$ $b_2$
:
$w_N$ $b_N$
The first line provides the number of areas $N$ ($1 \leq N \leq 10000$). Each of the subsequent $N$ lines provides the number of white stones $w_i$ and black stones $b_i$ ($1 \leq w_i, b_i \leq 100$) in the $i$-th area.
Output
Output
0
if Koshiro wins and
1
if Ukiko wins.
Sample Input 1
4
24 99
15 68
12 90
95 79
Sample Output 1
0
Sample Input 1
3
2 46
94 8
46 57
Sample Output 2
1

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef pair<int,int> pi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define drep(i,a,n) for(int i=a;i>n;i--)
#define Yes(ans) {cout<<(ans?"Yes":"No")<<endl;}
#define printv(vec) {rep(iti_,0,vec.size()) cout<<vec[iti_]<<" "; cout<<endl;}
#define printvv(vec) {rep(ni_,0,vec.size()) printv(vec[ni_]); cout<<endl;}
#define all(x) x.begin(),x.end()
#define so(x) sort(all(x))
#define re(x) reverse(all(x))
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;}}
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;}}
int main(){
    int n; cin>>n;
    int m=300;
    vvi dp(m,vi(m,-1));
    //dp[0][0]=0;
    rep(j,0,m){
        rep(i,0,m){
            //if(i==0&&j==0) continue;
            vi candi={};
            if(i>0) candi.push_back(dp[i-1][j]);
            rep(k,1,i+1){
                if(j-k<0) break;
                candi.push_back(dp[i][j-k]);
            }
            if(i+1<m&&j-1>=0) candi.push_back(dp[i+1][j-1]);
            so(candi);
            candi.erase(unique(all(candi)),candi.end());
            candi.push_back(candi.size()+1);
            rep(k,0,candi.size()){
                if(candi[k]!=k){
                    dp[i][j]=k;
                    break;
                }
            }
        }
    }
    int nim=0;
    rep(i,0,n){
        int x,y; cin>>x>>y;
        nim^=dp[x][y];
    }
    //vvi dp_(m,vi(m)); rep(i,0,m) rep(j,0,m) dp_[i][j]=dp[j][i];
    //printvv(dp_);
    //cout<<nim<<endl;
    if(nim==0) cout<<1<<endl;
    else cout<<0<<endl;
}
accuracy: 1
time_ms: 80
memory_kb: 3968
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int maxi = 210;
	vector dp(maxi, vector<int>(maxi, -1)); // i == white
	dp[0][0] = 0;
	rep(j, 0, maxi) rep(i, 0, maxi) {
		if (dp[i][j] != -1) continue;
		
		set<int> S;
		if (i >= 1) S.insert(dp[i - 1][j]);
		rep(t, 1, i + 1) if (j - t >= 0) S.insert(dp[i][j - t]);
		if (j >= 1 && i + 1 < maxi) S.insert(dp[i + 1][j - 1]);
		
		int cnt = 0;
		while (true) {
			if (!S.count(cnt)) {
				dp[i][j] = cnt;
				break;
			}
			++cnt;
		}
	}
	
	int N;
	cin >> N;
	
	int sum = 0;
	rep(i, 0, N) {
		int w, b;
		cin >> w >> b;
		sum ^= dp[w][b];
	}
	
	cout << (sum == 0 ? 1 : 0) << '\n';
}
accuracy: 1
time_ms: 180
memory_kb: 3628
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    vector<vector<int>> dp(101,vector<int>(201)); //black,white
    for(int b=0;b<=100;b++){
        for(int w=0;w<=200;w++){
            set<int> S;
            if(w>0) S.insert(dp[b][w-1]);
            for(int b2=1;b2<=min(b,w);b2++) S.insert(dp[b-b2][w]);
            if(b>0&&w<200) S.insert(dp[b-1][w+1]);
            for(int a=0;true;a++){
                if(!S.count(a)){dp[b][w]=a; break;}
            }
        }
    }

    int N; cin>>N;
    int ans=0;
    for(int i=0;i<N;i++){
        int w,b; cin>>w>>b;
        ans^=dp[b][w];
    }
    if(ans==0) cout<<1<<endl;
    else cout<<0<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3504
final_rank: 2

code_snippet: #include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> P;
constexpr ll mod = 1000000007;
int grundy[202][202];
signed main(){
	for(int ij=1;ij<=402;ij++){
		for(int j=0;j<=201;j++){
			int i=ij-j;
			if(0>i||201<i)continue;
			unordered_set<int>S;
			if(i)S.insert(grundy[i-1][j]);
			if(j)S.insert(grundy[i+1][j-1]);
			for(int k=j-1;k>=max(0,j-i);k--)S.insert(grundy[i][k]);
			for(int x=0;x<=205;x++){
				if(S.find(x)==S.end()){
					grundy[i][j]=x;break;
				}
			}
		}
	}

	int n;cin>>n;
	int x=0;
	rep(i,n){
		int a,b;cin>>a>>b;
		x^=grundy[a][b];
	}
	if(x)cout<<0<<endl;
	else cout<<1<<endl;
}
accuracy: 1
time_ms: 130
memory_kb: 3608
final_rank: 10

code_snippet: // #ifndef ONLINE_JUDGE
// #define _GLIBCXX_DEBUG//[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4みたいなデバック中のTLEは防げないので注意
// #endif

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;


template<typename T> using vc = vector<T>;//prioriy_queueに必要なのでここにこれ書いてます
template<typename T> using vv = vc<vc<T>>;

//-------------1.型系---------------
using ll = long long;
ll INF = 2e18;

// #include <boost/multiprecision/cpp_int.hpp>//インストール的なのをしてないとできないので注意
// namespace multip = boost::multiprecision;
// //using lll = multip::cpp_int;//無制限を使いたいときはこっちを使う
// using lll = multip::int128_t;

using ld = long double;
using bl = bool;
// using mint = modint998244353;
//using mint = modint1000000007;
//using mint = modint;//使うときはコメントアウトを外す
//mint::set_mod(m);//使うときはコメントアウトを外す

template<class T> using pq = priority_queue<T, vc<T>>;//大きい順
template<class T> using pq_g = priority_queue<T, vc<T>, greater<T>>;//小さい順
//-----------------------------------



//-------------2.配列系--------------
using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>; using vvvvl = vv<vvl>;
using vs = vc<string>; using vvs = vv<string>;
using vb = vc<bl>; using vvb = vv<bl>; using vvvb = vv<vb>;
using vld = vc<ld>; using vvld = vv<ld>; using vvvld = vv<vld>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using vmint = vc<mint>; using vvmint = vv<mint>; using vvvmint = vv<vmint>;

//配列外参照対策のやつは一番上の行にあります

#define rep(i,n) for(ll i = 0; i < (n); ++i)//↓でrepを使うので書いてます
template<class T>istream& operator>>(istream& i, vc<T>& v) { rep(j, size(v))i >> v[j]; return i; }

using ar2 = array<ll, 2>;

//----------------------------------



//--------3.コード短縮化とか---------
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define nfor(i,s,n) for(ll i=s;i<n;i++)//i=s,s+1...n-1 ノーマルfor
#define dfor(i,s,n) for(ll i = (s)-1; i>=n;i--)//s-1スタートでnまで落ちる

#define nall(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

#define pb push_back
#define eb emplace_back
#define em emplace
#define pob pop_back


#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define YN {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}// if(a==b)YN;
#define dame cout<<-1<<endl


#define vc_unique(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define vc_rotate(v) rotate(v.begin(),v.begin()+1,v.end());

#define pop_cnt(s) ll(popcount(uint64_t(s)))

#define next_p(v) next_permutation(v.begin(),v.end())

//if (regex_match(s, regex("")))YN;//文字列sの判定を行う。コメントアウトを外して「""」の中に判定する内容を入れる

//-------------------------------




//---------4.グリッド系----------
vl di = { 0,1,0,-1 };//vl di={0,1,1,1,0,-1,-1,-1};
vl dj = { 1,0,-1,0 };//vl dj={1,1,0,-1,-1,-1,0,1};

bool out_grid(ll i, ll j, ll h, ll w) {//trueならcontinue
    return (!(0 <= i && i < h && 0 <= j && j < w));
}

#define vvl_kaiten_r(v) {ll n = size(v);vvl nx(n,vl(n));rep(i,n)rep(j,n)nx[j][n-i-1]=v[i][j];swap(nx,v);}//時計回りに90°回転
#define vvl_kaiten_l(v) {ll n = size(v);vvl nx(n,vl(n));rep(i,n)rep(j,n)nx[n-j-1][i]=v[i][j];swap(nx,v);}//反時計周りに90°回転

#define vs_kaiten_r(v) {ll n = size(v);vs nx(n,string(n,'.'));rep(i,n)rep(j,n)nx[j][n-i-1]=v[i][j];swap(nx,v);}//文字列版 時計回りに90°回転
#define vs_kaiten_l(v) {ll n = size(v);vs nx(n,string(n,'.'));rep(i,n)rep(j,n)nx[n-j-1][i]=v[i][j];swap(nx,v);}//文字列版　反時計周りに90°回転


#define vvl_tenti(v) {ll n = size(v);vvl nx(n,vl(n));rep(i,n)rep(j,n)nx[j][i]=v[i][j];swap(nx,v);}
#define vs_tenti(v) {ll n = size(v); vs nx(n, string(n,'.')); rep(i, n)rep(j, n)nx[j][i] = v[i][j]; swap(nx, v);}

//--------------------------------




//-----------5.数学系--------------
#define yu_qurid(x,y) ((x)*(x)+(y)*(y))//ユークリッド距離 sqrtはしてないなので注意
#define mannhattan(x1,x2,y1,y2) (abs(x1-x2)+abs(y1-y2)) // マンハッタン距離 = |x1-x2|+|y1-y2|

template<class T>T tousa_sum1(T l, T d, T r) {//初項,公差,末項 で総和を求める
    T wide = (r - l) / d + 1;
    return (l + r) * wide / 2;
}
template<class T>T tousa_sum2(T a, T d, T n) {//初項,交差,項数 で総和を求める
    return (a * 2 + d * (n - 1)) * n / 2;
}
ll kousa_kousuu(ll l, ll r, ll d) {//初項,末項,交差 で等差数列の項数を求める
    return (r - l) / d + 1;
}
// mint touhi_sum(mint a, mint r, ll n) {//初項,公比,項数で等比数列の総和を求める
//     if (r == 1) {
//         return a * n;
//     }
//     mint bunsi = a * (r.pow(n) - mint(1));
//     mint bunbo = r - 1;
//     return bunsi / bunbo;
// }

ll nc2(ll x) { return x * (x - 1) / 2; }
ll nc3(ll x) { return x * (x - 1) * (x - 2) / 6; }

//----------------------------------------------




//-----------6.デバックや出力系------------------
void print(ld x) { printf("%.20Lf\n", x); }

void mukou_debug(vvl to, bool yukou) {//GRAPH × GRAPH用の無向グラフを出力する
    ll n = size(to); ll cnt = 0;//辺の本数
    vc<pair<ll, ll>>v; rep(i, n)for (ll t : to[i])  if (i < t || yukou)cnt++, v.eb(i + 1, t + 1);//有向グラフなら全部OK、違うなら無向なのでf<tのみ見る、using Pのやつを別のにしたいときのためにPを使わずにpair<ll,ll>にしてる
    cout << n << ' ' << cnt << endl; for (auto [f, t] : v)cout << f << ' ' << t << endl;
}

#define vc_cout(v){ll n = size(v);rep(i,n)cout<<v[i]<<endl;}//一次元配列を出力する
#define vv_cout(v){ll n = size(v);rep(i,n){rep(j,size(v[i])){cout<<v[i][j]<<' ';}cout<<endl;}}//二次元配列を出力する

int main(){
    ll n;
    cin >> n;

    vvl dp(110, vl(230, -1)); // dp[i][j]: 黒i個、白j個の場合のGrundy数
    dp[0][0] = 0;
    rep(i, 101) rep(j, 201){
        set<ll> st;

        // 白を1つ取り除く
        if(j-1 >= 0) st.insert(dp[i][j-1]);

        // 黒を取り除く
        rrep(k, j){
            if(i-k >= 0) st.insert(dp[i-k][j]);
        }

        // 黒を白に交換
        if(i-1 >= 0) st.insert(dp[i-1][j+1]);

        ll res = 0;
        while(st.count(res)) res++;
        dp[i][j] = res;
    }

    ll ans = 0;

    rep(i, n){
        ll w, b;
        cin >> w >> b;
        ans ^= dp[b][w];
    }

    if(ans) cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3700
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
random_device seed_gen;
mt19937_64 rnd(seed_gen());
template <typename T> bool chmax(T& A, T B) { if (A < B) { A = B; return true; } return false; }
template <typename T> bool chmin(T& A, T B) { if (A > B) { A = B; return true; } return false; }
#define rep(i, m, n) for (int i = (m); i < (n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using ll = long long;
using pint = pair<int, int>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
#define PI 3.14159265358979323846264338327950288419716939937510
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    vector<vector<int>> g(201, vector<int>(101));
    vector<vector<int>> f(201, vector<int>(101));
    g[0][0] = 0;
    f[0][0] = 1;
    auto dfs = [&](auto dfs, int w, int b) {
        if (f[w][b]) {
            return g[w][b];
        }
        f[w][b] = 1;
        set<int> st;
        if (w >= 1) {
            st.emplace(dfs(dfs, w - 1, b));
        }
        rep (i, 1, w + 1) {
            if (b - i >= 0) {
                st.emplace(dfs(dfs, w, b - i));
            }
        }
        if (b >= 1) {
            st.emplace(dfs(dfs, w + 1, b - 1));
        }
        rep (i, 0, st.size() + 1) {
            if (st.count(i) == false) {
                return g[w][b] = i;
            }
        }
    };
    rep (w, 0, 101) {
        rep (b, 0, 101) {
            dfs(dfs, w, b);
        }
    }
    int n;
    cin >> n;
    int xs = 0;
    rep (i, 0, n) {
        int w, b;
        cin >> w >> b;
        xs ^= g[w][b];
    }
    cout << (xs ? 0 : 1) << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3920
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
#define yes "Yes"
#define no "No"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
const vector<char> alpha = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const ll INF = 1000000007;
const ll MOD=998244353;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
vvi dp(201,vector<int>(201,-1));
int func(int w,int b){
    if (w==0&&b==0) return 0;
    if (dp[w][b]!=-1) return dp[w][b];
    
    unordered_set<int> st;
    if (w!=0) st.insert(func(w-1,b));
    FOR(k,1,min(b,w)+1) st.insert(func(w,b-k));
    if (b!=0) st.insert(func(w+1,b-1));

    int g=0;
    while(st.count(g)) g++;
    return dp[w][b]=g;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<int> W(N), B(N);
    int res=0;
    for(int i=0;i<N;i++){
        cin >> W[i] >> B[i];
        res^= func(W[i],B[i]);
    }

    cout << (res != 0 ? 0 : 1) << "\n";
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3952
final_rank: 9

code_snippet: #ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG //[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4みたいなデバック中のTLEは防げないので注意
#endif
#include <bits/stdc++.h>

// #include <atcoder/all>
// using namespace atcoder;

using namespace std;
using ll = long long;
ll INF = 2e18;
using P = pair<ll, ll>;
#define pb push_back
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reprev(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define for_(i, a, b) for (ll i = (a); i < (b); i++)
#define all(v) v.begin(), v.end()
template <typename T>
inline bool chmin(T &a, const T &b)
{
  bool c = a > b;
  if (c)
    a = b;
  return c;
}
template <typename T>
inline bool chmax(T &a, const T &b)
{
  bool c = a < b;
  if (c)
    a = b;
  return c;
}
template <typename T>
inline T ceil(T a, T b) { return (a + (b - 1)) / b; }
// using mint = modint998244353;
// using mint = modint1000000007;
// using mint = static_modint<10>;//使うときはコメントアウトを外す
template <typename T>
using vc = vector<T>;
template <class T>
istream &operator>>(istream &i, vc<T> &v)
{
  rep(j, size(v)) i >> v[j];
  return i;
}
template <class T>
ostream &operator<<(ostream &o, const vc<T> &v)
{
  rep(j, size(v))
  {
    if (j)
      o << " ";
    o << v[j];
  }
  o << endl;
  return o;
}
vc<vc<ll>> dp(201, vc<ll>(101, -1));
ll grundy(ll w, ll b)
{
  if (dp[w][b] != -1)
  {
    return dp[w][b];
  }
  if (w == 0 && b == 0)
  {
    return 0;
  }
  set<ll> s;
  if (w > 0)
  {
    s.insert(grundy(w - 1, b));
  }
  if (b > 0)
  {
    reps(i, min(w, b))
    {
      s.insert(grundy(w, b - i));
    }
    s.insert(grundy(w + 1, b - 1));
  }
  ll res = 0;
  while (s.count(res))
  {
    res++;
  }
  return dp[w][b] = res;
}
int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // ref:https://rsk0315.hatenablog.com/entry/2020/05/09/170315
  ll N;
  cin >> N;
  vc<ll> W(N), B(N);
  rep(i, N)
  {
    cin >> W[i] >> B[i];
  }
  ll ans = 0;
  rep(i, N)
  {
    ans ^= grundy(W[i], B[i]);
  }
  if (ans == 0)
  {
    cout << "1" << endl;
  }
  else
  {
    cout << "0" << endl;
  }
  //  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4116
final_rank: 11

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	int grandy[201][201];
	for(int i = 0; i <=200; i++){
		for(int j = 0; j <= 200; j++){
			grandy[i][j] = 0;
		}
	}
	for(int j = 0; j <=100; j++){
		for(int i = 0; i <= 200; i++){
			vector<int> a;
			if(i>0){
				a.push_back(grandy[i-1][j]);
			}
			if(j>0){
				a.push_back(grandy[i+1][j-1]);
			}
			for(int k = 1; k <= i && j>=k; k++){
				a.push_back(grandy[i][j-k]);
			}
			sort(a.begin(), a.end());
			int tmp = 0;
			for(int i = 0; i < a.size(); i++){
				if(tmp == a[i])tmp++;
			}
			grandy[i][j] = tmp;
		}
	}
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
//			cout << grandy[i][j] << " ";
		}
//		cout << endl;
	}
	int ans = 0;
	int w,b;
	for(int i = 0; i < n; i++){
		cin >> w >> b;
		ans ^= grandy[w][b];
	}
	if(ans==0)cout << 1 << endl;
	else cout << 0 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3616
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin >> N;

    //黒石は増えない。白石は一個増える
    vector<vector<int>> mex(222,vector<int>(222,0));

    rep(i,220){
        rep(j,220){
            set<int> a;
            if(j>=1) a.insert(mex[i][j-1]);
            rep(k,min(j,i)) a.insert(mex[i-k-1][j]);
            if(i>=1) a.insert(mex[i-1][j+1]);
            a.insert(1e9);

            int k=0;
            for(int e:a){
                if(e!=k){
                    mex[i][j]=k;
                    break;
                }
                k++;
            }
        }
    }

    // rep(i,10){
    //     rep(j,10) cout << mex[i][j] << " ";
    //     cout << endl;
    // }

    int x = 0;
    rep(i,N){
        int w,b;
        cin >> w >> b;
        x ^= mex[b][w];
    }
    cout << (x==0) << endl;

}
accuracy: 1
time_ms: 180
memory_kb: 3668
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin >> N;

    //黒石は増えない。白石は一個増える
    vector<vector<int>> mex(222,vector<int>(222,0));

    rep(i,220){
        rep(j,220){
            vector<int> a;
            if(j>=1) a.push_back(mex[i][j-1]);
            rep(k,min(j,i)) a.push_back(mex[i-k-1][j]);
            if(i>=1) a.push_back(mex[i-1][j+1]);
            a.push_back(1e9);
            sort(a.begin(),a.end());

            rep(k,a.size()){
                if(a[k]!=k){
                    mex[i][j]=k;
                    break;
                }
            }
        }
    }

    // rep(i,10){
    //     rep(j,10) cout << mex[i][j] << " ";
    //     cout << endl;
    // }

    int x = 0;
    rep(i,N){
        int w,b;
        cin >> w >> b;
        x ^= mex[b][w];
    }
    cout << (x==0) << endl;

}
accuracy: 0.047619047619047616
time_ms: 20
memory_kb: 3652
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define overload(a,b,c,d,...) d
#define rep1(i,n) for(ll i=0;i<(ll)n;++i)
#define rep2(i,l,r) for(ll i=(ll)l;i<(ll)r;++i)
#define rep(...) overload(__VA_ARGS__,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for(ll i=(ll)(n)-1;i>=0;--i)
#define rrep2(i,l,r) for(ll i=(ll)(r)-1;i>=(ll)l;--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back

using vl=vector<ll>;

int main(){
	ll n;cin>>n;
	vl w(n),b(n);
	rep(i,n)cin>>w[i]>>b[i];
	vector<vl> grundy(201,vl(201,-1)); //(白,黒)
	grundy[0][0]=0;
	rep(s,1,201){
		rrep(i,s+1){
			ll j=s-i;
			vl tmp;
			if(i-1>=0)tmp.eb(grundy[i-1][j]);
			rep(k,1,i+1)if(j-k>=0)tmp.eb(grundy[i][j-k]);
			if(j>0)tmp.eb(grundy[i+1][j-1]);
			sort(all(tmp));
			ll g=0;
			for(auto e:tmp)if(e==g)g++;
			grundy[i][j]=g;
			
		}
	}
	ll g=0;
	rep(i,n){
		g^=grundy[w[i]][b[i]];
	}
	if(g==0)cout<<1<<endl;
	else cout<<0<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3912
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pint = pair<int, int>;
constexpr double PI = 3.141592653589793;
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr ll INF = 1LL << 60;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
#define vec2d(T, name, n, m, ini) vector<vector<T>> name(n, vector<T>(m, ini))
#define vec3d(T, name, n, m, l, ini) \
  vector<vector<vector<T>>> name(n, vector<vector<T>>(m, vector<T>(l, ini)))
#define REP(i, e) rep(i, 0, e)
#define rep(i, s, e) for (ll i = s; i < (e); ++i)
#define rrep(i, s, e) for (ll i = s; i >= (e); --i)
#define all(x) (x).begin(), (x).end()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vec2d(int, grundy, 201, 201, 0);
  REP(b, 201) REP(w, 201) {
    if (b == 0 && w == 0) continue;
    unordered_set<int> tmps;
    if (w > 0) tmps.insert(grundy[w - 1][b]);
    if (b > 0 && w < 200) tmps.insert(grundy[w + 1][b - 1]);
    rep(i, 1, min(w, b) + 1) tmps.insert(grundy[w][b - i]);
    int tmp = 0;
    while (tmps.find(tmp) != tmps.end()) ++tmp;
    grundy[w][b] = tmp;
  }

  vector<int> w(n), b(n);
  REP(i, n) cin >> w[i] >> b[i];
  int nim = grundy[w[0]][b[0]];
  rep(i, 1, n) nim = nim xor grundy[w[i]][b[i]];
  cout << (nim == 0) ? 1 : 0;
  cout << "\n";

  return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3704
final_rank: 13

code_snippet: // 石遊び
#include <bits/stdc++.h>
// #include <atcoder/all>
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long;
template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, f, n) for (int i = (int) f; i < (int)(n); i++)
#define repd(i, n, l) for (int i = (int) n; i >= (int) l; i--)

const ll inf = 1LL<<60 ;

const int B = 209;

int grundy[B][B]; // 白石がi個、黒石がj個のときのgrundy数

int mex(set<int> st){
    if (st.size() == 0) return 0;
    int ans = 0;
    for(int i = 0; i<1000; i++){
        if (st.count(i) == 0) {
            ans = i;
            break;
        }
    }
    return ans;
}

void calc() {
    grundy[0][0] = 0;
    set<int> st;
    for (int b = 0; b < B-1; b++){
        for (int w = 0; w < B-1; w++){
            if (w == 0 && b == 0) continue;
            if (w > 0) st.insert(grundy[w-1][b]);
            if (b > 0) st.insert(grundy[w+1][b-1]);
            if (b > 0) {
                for (int t = 1; t <= w; t++){
                    if (b-t >= 0) st.insert(grundy[w][b-t]);
                }
            }
            grundy[w][b] = mex(st);
            st.clear();
        }
    }
}

int main() {
    int n; 
    cin >> n;
    calc();
    int t;
    for (int i = 0; i<n; i++){
        int a, b;
        cin >> a >> b;
        if (i == 0) t = grundy[a][b];
        else t ^= grundy[a][b];
    }
    if (t == 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 3616
final_rank: 16

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <tuple>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <map>
#include <set>
#include <functional>

#define rep(i, m, n) for (ll i=m; i<n; i++)
#define rept(i, m, n) for (ll i=m; i<=n; i++)
#define repi(n) for (ll i=0; i<n; i++)
#define repi1(n) for (ll i=1; i<=n; i++)
#define repj(n) for (ll j=0; j<n; j++)
#define repj1(n) for (ll j=1; j<=n; j++)
#define repk(n) for (ll k=0; k<n; k++)
#define repk1(n) for (ll k=1; k<=n; k++)

#define ALL(x) begin(x), end(x)

#define YY cout<<"Yes"<<endl;
#define NN cout<<"No"<<endl;

#define FLOOR(x, y) ((x)/(y)-((x)%(y)<0))
#define CEIL(x, y) (FLOOR((x)+(y)-1,(y)))
#define RES(x, y) ((x)-FLOOR((x),(y))*(y))
#define SEPL(i, n) ((i==n-1)?'\n':' ')
#define CHMAX(x, y) x=max(x,y);
#define CHMIN(x, y) x=min(x,y);

#define nextcon(nx, ny, h, w) (0<=nx && nx<h && 0<=ny && ny<w)
#define nxnycon (0<=nx && nx<h && 0<=ny && ny<w)
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int dx8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pll = pair<ll, ll>;
using graph = vector<vector<ll>>;
using wgraph = vector<vector<pair<ll, ll>>>;

const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 998244353;

#include <algorithm>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;
using graph = vector<vector<ll>>;
using wgraph = vector<vector<pair<ll, ll>>>;

ll next_n_adic_number(ll n, vector<ll> &d);
vector<ll> eratosthenes(ll n);
ll digit(ll x);
vector<ll> divs(ll n);
map<ll, ll> factorization(ll n);
map<ll, ll> factorization(ll n, vector<ll> plist);
ll mex(vector<ll> v);


// 次のn進数
ll next_n_adic_number(ll n, vector<ll> &d) {
    ll m = d.size();
    for (ll i = 0; i < m; i++) {
        if (d[i] < n) {
            d[i]++;
            return 1;
        } else {
            d[i] = 0;
        }
    }
    return 0;
}

vector<ll> eratosthenes(ll n){ // 1 ~ n
    vector<ll> is_prime, plist;
    is_prime.resize(n+1, 1);
    is_prime[1]=0;
    for(ll i=1; i<=n; i++){
        if(is_prime[i]){
            for(ll j=2; j<=n/i; j++){
                is_prime[i*j]=0;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        if(is_prime[i])plist.push_back(i);
    }
    return plist;
}

ll digit(ll x){
    ll ret=0;
    while(x){
        ret++;
        x/=10;
    }
    return ret;
}

vector<ll> divs(ll n){
    vector<ll> ret;
    for(ll i=1; i<=floor(sqrt(n)); i++){
        if(!(n%i))ret.push_back(i);
        if(!(n%i))ret.push_back(n/i);
    }
    sort(ret.begin(), ret.end());
    return ret;
}

map<ll, ll> factorization(ll n){
    map<ll, ll> ret;
    ll m=n;
    for(ll i=2; i*i<=n; i++){
        if(!(m%i)){
            ll c=0;
            for(;!(m%i);m/=i){
                c++;
            }
            ret[i]=c;
        }
    }
    if(m!=1){
        ret[m]=1;
    }
    return ret;
}

map<ll, ll> factorization(ll n, vector<ll> plist){
    map<ll, ll> ret;
    ll m=n;
    for(auto i:plist){
        if(!(m%i)){
            ll c=0;
            for(;!(m%i);m/=i){
                c++;
            }
            ret[i]=c;
        }
    }
    if(m!=1){
        ret[m]=1;
    }
    return ret;
}

ll mex(vector<ll> v){
    sort(v.begin(), v.end());
    for(ll i=0; i<=v.size(); i++){
        if(!binary_search(v.begin(), v.end(), i)){
            return i;
        }
    }
    return -1;
}

int main(){
    vvl gd(300,vl(300));
    repj(300)repi(300){
        if(i==1&&j==1){
            ll aaa=3;
        }
        vl v;
        if(i>0)v.push_back(gd[i-1][j]);
        if(i<299&&j>0)v.push_back(gd[i+1][j-1]);
        repk(min(i,j)){
            v.push_back(gd[i][j-k-1]);
        }

        gd[i][j]=mex(v);
    }
    ll n;
    cin>>n;
    ll ga=0;
    repi(n){
        ll w,b;
        cin>>w>>b;
        ga^=gd[w][b];
    }
    cout<<(ga==0)<<endl;
}
accuracy: 1
time_ms: 200
memory_kb: 4196
final_rank: 18

code_snippet: #ifndef ONLINE_JUDGE//なんか手元ではデバックモードになって、atcoder上ではデバックモードにならないらしい ABC325Dはこれで通った
#define _GLIBCXX_DEBUG//[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4のデバックTLEなどに注意
#endif//これと上のONLINE JUDGEが絶対必要
//★TLEにならないはずなのにTLEになったらオンラインジャッジを消してデバックモードのまま提出をする。

#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS//これを消すとvisual studioがバグる
#define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS//これを消すとvisual studioがバグる

#include <bits/stdc++.h>
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;

//#include <atcoder/all>
//using namespace atcoder;

//using mint = modint;//modを自分で設定したい場合に使う↓のset_modをする　これを外側で書く
//mint::set_mod(m);//これでmがmodになる ABC282-E　これをmain関数内で書く

//using mint = modint998244353;//mintはchminができない
//using mint = modint1000000007;//mintはchminができない
//using vmint = vc<mint>; using vvmint = vv<mint>; using vvvmint = vv<vmint>;
//mint im = mint(1)/m;//modの割り算はlogがかかるらしいから a/m をするなら a*imをすること。int/intをするとmintにしてくれないのでmint(int)/intとかにしないといけない。
//return (mint(x).pow(y) + mint(y).pow(x)).val();//ACLでmodpowを求めてからint型で返したいときに使う ABC282-E
#define fi first
#define se second
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define nfor(i,s,n) for(ll i=s;i<n;i++)//i=s,s+1...n-1 ノーマルfor
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define rfor(i,s,n) for(ll i = s;i<=n;i++)//i=s,s-1...n
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define dfor(i,s,n) for(ll i = (s)-1; i>=n;i--)//s-1スタートでnまで落ちる
#define nall(a) a.begin(),a.end()//ノーマルオール
#define rall(a) a.rbegin(),a.rend()//R入りオール
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pb push_back
#define eb emplace_back
#define em emplace
#define pob pop_back()
#define dame {cout<<-1<<endl;}
#define N {cout<<"No"<<endl;}
#define YN {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}// if(ans[i])YN;
#define cout(n) cout<<n<<endl;
#define bit(n) (ll(1)<<(n))
#define vcunique(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
//using lll = __int128;//paizaとatcoderのジャッジだけ使える、visual studioは上の多倍長整数のlllを使ってください。
using ld = long double;
using bl = bool;
using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>; using vvvvl = vv<vvl>;
using vs = vc<string>; using vvs = vv<string>;
using vb = vc<bl>; using vvb = vv<bl>; using vvvb = vv<vb>;
using vld = vc<ld>; using vvld = vv<ld>; using vvvld = vv<vld>;
using P = pair<ll, ll>;
using P2 = array<P, 2>;//ABC339-D めちゃくちゃ早くなる
//pq<ll>q;
template<class T> using pq = priority_queue<T, vc<T>>;//★大きい順に取り出す コスト,頂点 bfs系で使う　小さい順じゃないですABC305E
template<class T> using pq_g = priority_queue<T, vc<T>, greater<T>>;//小さい順に取り出す　ダイクストラ法で使う
//-----------------
ll pow2(ll x) { return x * x; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }//snukeさんのライブラリ集から貰ってきた
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<class T>T tousa_sum1(T l, T d, T r) {//初項,交差,末項 で総和を求める 負でも使える
    T wide = (r - l) / d + 1;
    return (l + r) * wide / 2;//((初項+末項)*項数)/2
}
template<class T>T tousa_sum2(T a, T d, T n) {//初項,交差,項数 で総和を求める、負でも正でも使える,1や-1の直書きintに注意
    return (a * 2 + d * (n - 1)) * n / 2;
}
ll c2(ll x) { return x * (x - 1) / 2; }
ll c3(ll x) { return x * (x - 1) * (x - 2) / 6; }
//----------------
vl dx = { 1,0,-1,0 };//vl dx={1,1,0,-1,-1,-1,0.1};
vl dy = { 0,1,0,-1 };//vl dy={0,1,1,1,0,-1,-1,-1};
ll INF = 2e18;
ll D = 61;//ダブリングの桁 2^61ならINFが収まってくれる ARC60-E
//if(regex_match(s, regex("")))YN;//search
//ll k = popcount(uint64_t(s));//sはlonglong型、符号なしの型にする。
//ll(1)<<60  2^60>1e18

//------------------------------------------
map<P, ll>mp;
ll f(ll a, ll b) {//白,黒
    if(mp.count(P(a,b)))return mp[P(a,b)];  
    //ア、イ、ウのどれか一つから選べるということで順番に一個ずつというわけではなかった(´・ω・｀)
    unordered_set<ll>st;//mexを求める用
    if (a >= 1)st.insert(f(a - 1, b));//(ア)をする
    
    ll can = a ;//取れる最大の個数
    nfor(i, 1, can+1) {//canだけだとcanそのものは取れない
        if (b - i < 0)break;//もう取れないからbreak
        //if (b - i == 0) {//0ならゲームの操作ができない
        //    st.insert(0);//0じゃなくね？とか思ってたけど問題文をそもそも読み間違えてた黒が0になっても白があれば(ア)ができる
        //    break;
        //}
        st.insert(f(a, b - i));
    }
    if (b >= 1)st.insert(f(a + 1, b - 1));//黒を白にしてその白を盤面のものとするらしい消えるのかと思ってた
    ll res = 0;
    while (st.count(res))res++;
    return mp[P(a, b)] = res;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        ans ^= f(a, b);
    }
    if (ans == 0)cout << 1 << endl;
    else cout << 0 << endl;
}
accuracy: 1
time_ms: 100
memory_kb: 4728
final_rank: 17

code_snippet: #ifndef ONLINE_JUDGE//なんか手元ではデバックモードになって、atcoder上ではデバックモードにならないらしい ABC325Dはこれで通った
#define _GLIBCXX_DEBUG//[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4のデバックTLEなどに注意
#endif//これと上のONLINE JUDGEが絶対必要
//★TLEにならないはずなのにTLEになったらオンラインジャッジを消してデバックモードのまま提出をする。

#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS//これを消すとvisual studioがバグる
#define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS//これを消すとvisual studioがバグる

#include <bits/stdc++.h>
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;

//#include <atcoder/all>
//using namespace atcoder;

//using mint = modint;//modを自分で設定したい場合に使う↓のset_modをする　これを外側で書く
//mint::set_mod(m);//これでmがmodになる ABC282-E　これをmain関数内で書く

//using mint = modint998244353;//mintはchminができない
//using mint = modint1000000007;//mintはchminができない
//using vmint = vc<mint>; using vvmint = vv<mint>; using vvvmint = vv<vmint>;
//mint im = mint(1)/m;//modの割り算はlogがかかるらしいから a/m をするなら a*imをすること。int/intをするとmintにしてくれないのでmint(int)/intとかにしないといけない。
//return (mint(x).pow(y) + mint(y).pow(x)).val();//ACLでmodpowを求めてからint型で返したいときに使う ABC282-E
#define fi first
#define se second
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define nfor(i,s,n) for(ll i=s;i<n;i++)//i=s,s+1...n-1 ノーマルfor
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define rfor(i,s,n) for(ll i = s;i<=n;i++)//i=s,s-1...n
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define dfor(i,s,n) for(ll i = (s)-1; i>=n;i--)//s-1スタートでnまで落ちる
#define nall(a) a.begin(),a.end()//ノーマルオール
#define rall(a) a.rbegin(),a.rend()//R入りオール
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pb push_back
#define eb emplace_back
#define em emplace
#define pob pop_back()
#define dame {cout<<-1<<endl;}
#define N {cout<<"No"<<endl;}
#define YN {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}// if(ans[i])YN;
#define cout(n) cout<<n<<endl;
#define bit(n) (ll(1)<<(n))
#define vcunique(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
//using lll = __int128;//paizaとatcoderのジャッジだけ使える、visual studioは上の多倍長整数のlllを使ってください。
using ld = long double;
using bl = bool;
using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>; using vvvvl = vv<vvl>;
using vs = vc<string>; using vvs = vv<string>;
using vb = vc<bl>; using vvb = vv<bl>; using vvvb = vv<vb>;
using vld = vc<ld>; using vvld = vv<ld>; using vvvld = vv<vld>;
using P = pair<ll, ll>;
using P2 = array<P, 2>;//ABC339-D めちゃくちゃ早くなる
//pq<ll>q;
template<class T> using pq = priority_queue<T, vc<T>>;//★大きい順に取り出す コスト,頂点 bfs系で使う　小さい順じゃないですABC305E
template<class T> using pq_g = priority_queue<T, vc<T>, greater<T>>;//小さい順に取り出す　ダイクストラ法で使う
//-----------------
ll pow2(ll x) { return x * x; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }//snukeさんのライブラリ集から貰ってきた
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<class T>T tousa_sum1(T l, T d, T r) {//初項,交差,末項 で総和を求める 負でも使える
    T wide = (r - l) / d + 1;
    return (l + r) * wide / 2;//((初項+末項)*項数)/2
}
template<class T>T tousa_sum2(T a, T d, T n) {//初項,交差,項数 で総和を求める、負でも正でも使える,1や-1の直書きintに注意
    return (a * 2 + d * (n - 1)) * n / 2;
}
ll c2(ll x) { return x * (x - 1) / 2; }
ll c3(ll x) { return x * (x - 1) * (x - 2) / 6; }
//----------------
vl dx = { 1,0,-1,0 };//vl dx={1,1,0,-1,-1,-1,0.1};
vl dy = { 0,1,0,-1 };//vl dy={0,1,1,1,0,-1,-1,-1};
ll INF = 2e18;
ll D = 61;//ダブリングの桁 2^61ならINFが収まってくれる ARC60-E
//if(regex_match(s, regex("")))YN;//search
//ll k = popcount(uint64_t(s));//sはlonglong型、符号なしの型にする。
//ll(1)<<60  2^60>1e18

//------------------------------------------
map<P, ll>mp;
ll f(ll a, ll b) {//白,黒
    if(mp.count(P(a,b)))return mp[P(a,b)];
    if (a == 0)return 0;//自分が取れないならここに来る直前のやつのmexのために0にできることを渡す
    unordered_set<ll>st;//mexを求める用
    ll can = a - 1;//取れる最大の個数
    nfor(i, 1, can) {
        if (b - i < 0)break;//もう取れないからbreak
        if (b - i == 0) {//0ならゲームの操作ができない
            st.insert(0);//0じゃなくね？
            break;
        }
        st.insert(f(a - 1, b - i));
    }
    ll res = 0;
    while (st.count(res))res++;
    return mp[P(a, b)] = res;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        ans ^= f(a, b);
    }
    if (ans == 0)cout << 1 << endl;
    else cout << 0 << endl;
}
accuracy: 0.023809523809523808
time_ms: 10
memory_kb: 3700
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;

  vector<int> w(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> b[i];
  }

  vector<vector<int>> dp(201, vector<int>(201, -1));
  auto dfs = [&](auto dfs, int W, int B) -> int {
    if (dp[W][B] != -1) {
      return dp[W][B];
    }
    if (W == 0 && B == 0) {
      return dp[W][B] = 0;
    }
    int ret;
    vector<int> grundy;
    
    if (W - 1 >= 0) {
      ret = dfs(dfs, W - 1, B);
      grundy.push_back(ret);
    }
    for (int i = 1; i <= W; i++) {
      if (B - i >= 0) {
        ret = dfs(dfs, W, B - i);
        grundy.push_back(ret);
      }
    }
    if (B - 1 >= 0) {
      ret = dfs(dfs, W + 1, B - 1);
      grundy.push_back(ret);
    }
    sort(grundy.begin(), grundy.end());
    grundy.erase(unique(grundy.begin(), grundy.end()), grundy.end());
    for (int i = 0; i < (int)grundy.size(); i++) {
      if (i != grundy[i]) {
        dp[W][B] = i;
        return dp[W][B];
      }
    }
    dp[W][B] = (int)grundy.size();
    return dp[W][B];
  };

  int MAX = dfs(dfs, 100, 100);
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans ^= dp[w[i]][b[i]];
  }

  cout << (ans == 0 ? 1 : 0) << '\n';
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3768
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int dp[201][101];

int main()
{
    int n;
    cin >> n;
    vector<int> w(n), b(n);
    rep(i,n) cin >> w[i] >> b[i];
    for(int B=0;B<=100;B++)for(int W=0;W<=200;W++){
        set<int> st;
        if(W>=1) st.insert(dp[W-1][B]);
        if(B>=1) st.insert(dp[W+1][B-1]);
        for(int i=1;i<=W;i++){
            if(B-i>=0) st.insert(dp[W][B-i]);
        }
        for(int i=0;i<300;i++){
            if(st.count(i)) continue;
            dp[W][B] = i;
            break;
        }
    }
    int grundy = 0;
    rep(i,n){
        grundy ^= dp[w[i]][b[i]];
    }
    if(grundy==0){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3592
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<P> vp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define pb emplace_back
#define all(a) a.begin(),a.end()
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
template<class T> void out(T a){cout<<a<<'\n';}
const ll inf=1001001001001001001;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    vvi dp(210,vi(105));
    rep(j,105)rep(i,210){
            vi al;
            if(i-1>=0)al.pb(dp[i-1][j]);
            REP(t,1,i+1)if(j-t>=0)al.pb(dp[i][j-t]);
            if(j-1>=0&&i+1<210)al.pb(dp[i+1][j-1]);
            dupli(al);
            al.pb(inf);
            rep(t,al.size()){
                if(al[t]!=t){
                    dp[i][j]=t;
                    break;
                }
            }
    }
    ll n;cin>>n;
    ll res=0;
    rep(t,n){
        ll a,b;cin>>a>>b;
        res^=dp[a][b];
    }
    out(1-min(res,1ll));
}
accuracy: 1
time_ms: 10
memory_kb: 3628
final_rank: 3