QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#17861#992. Number of Colorful MatchingsQingyuAC ✓88ms6372kbC++206.6kb2022-01-12 22:50:432022-05-04 16:08:01

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 16:08:01]
  • 评测
  • 测评结果:AC
  • 用时:88ms
  • 内存:6372kb
  • [2022-01-12 22:50:43]
  • 提交

answer

#include <bits/stdc++.h>

const int mod = 2;
inline int inc(int x, int y) { x += y - mod; return x + (x >> 31 & mod); }
inline int dec(int x, int y) { x -= y; return x + (x >> 31 & mod); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline void upd(int &x, int y) { x = inc(x, y); }
inline void dpu(int &x, int y) { x = dec(x, y); }
inline void pud(int &x, int y) { x = mul(x, y); }
inline int fastpow(int x, int p) {
	int r = 1;
	while (p) {
		if (p & 1) pud(r, x);
		pud(x, x);
		p >>= 1;
	}
	return r;
}

typedef std::vector<int> poly;

inline poly inc(poly x, poly y) {
	int t = std::max(x.size(), y.size());
	x.resize(t), y.resize(t);
	poly z(t);
	for (int i = 0; i < t; ++i)
		z[i] = inc(x[i], y[i]);
	return z;
}
inline void upd(poly &x, poly y) {
	x = inc(x, y);
}
inline poly dec(poly x, poly y) {
	int t = std::max(x.size(), y.size());
	x.resize(t), y.resize(t);
	poly z(t);
	for (int i = 0; i < t; ++i)
		z[i] = dec(x[i], y[i]);
	return z;
}
inline poly mul(poly x, poly y) {
	int nx = x.size(), ny = y.size();
	poly z(nx + ny - 1);
	for (int i = 0; i < nx; ++i)
		for (int j = 0; j < ny; ++j)
			upd(z[i + j], mul(x[i], y[j]));
	return z;
}


// solve det(A + I * z)
auto solve(int n, std::vector<std::vector<int>> a) {
	auto swap_row = [&](int i, int j) {
		for (int k = 0; k < n; ++k)
			std::swap(a[i][k], a[j][k]);
	};
	auto swap_col = [&](int i, int j) {
		for (int k = 0; k < n; ++k)
			std::swap(a[k][i], a[k][j]);
	};
	auto add_row = [&](int i, int j, int t) {
		for (int k = 0; k < n; ++k) {
			upd(a[i][k], mul(a[j][k], t));
		}
	};
	auto add_col = [&](int i, int j, int t) {
		for (int k = 0; k < n; ++k) {
			upd(a[k][i], mul(a[k][j], t));
		}
	};
	auto debug = [&]() {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) printf("%d ", a[i][j]);
			putchar('\n');
		}
	};
	auto gauss = [&]() {
		for (int i = 0; i + 1 < n; ++i) {
			int k = -1;
			for (int j = i + 1; j < n; ++j)
				if (a[j][i]) {
					k = j;
					break;
				}
			if (k == -1) continue;
			swap_row(i + 1, k);
			swap_col(i + 1, k);
			assert(a[i + 1][i] != 0);
			for (int j = i + 2; j < n; ++j) {
				int t = mul(a[j][i], fastpow(a[i + 1][i], mod - 2));
				add_row(j, i + 1, dec(0, t));
				add_col(i + 1, j, t);
				for (int z = 0; z <= i; ++z) {
					assert(a[j][z] == 0);
				}
			}
		}
	};
	gauss();
	std::vector<std::vector<int>> f(n, std::vector<int>());
	// det(I * z - S)
	auto output = [&](poly &P) {
		printf("poly: ");
		for (int x : P)
			printf("%d, ", x);
		putchar('\n');
	};
	f[0] = { a[0][0], 1 };
	for (int i = 1; i < n; ++i) {
		f[i] = mul(f[i - 1], poly{ a[i][i], 1 });
		int prod = a[i][i - 1], sgn = mod - 1;
		for (int j = i - 1; j >= 0; --j) {
			// f[i] += prod * a[j][n] * f[j - 1]
			poly z{1};
			if (j) z = f[j - 1];
			poly r = mul(z, poly{mul(a[j][i], mul(sgn, prod))});
			upd(f[i], r);
			if (j) pud(prod, a[j][j - 1]);
			sgn = dec(0, sgn);
		}
	}
	f[n - 1].resize(n + 1);
	return f[n - 1];
}

struct F2 {
	int a, b; // a + b * z
	F2(int a = 0, int b = 0) : a(a), b(b){
		
	}	
};

inline F2 inc(const F2 &lhs, const F2 &rhs) {
	return F2(inc(lhs.a, rhs.a), inc(lhs.b, rhs.b));
}
inline F2 dec(const F2 &lhs, const F2 &rhs) {
	return F2(dec(lhs.a, rhs.a), dec(lhs.b, rhs.b));
}
inline F2 mul(const F2 &lhs, int k) {
	return F2(mul(lhs.a, k), mul(lhs.b, k));
}
inline void upd(F2 &lhs, const F2 &rhs) {
	lhs = inc(lhs, rhs);
}
inline void pud(F2 &lhs, int k) {
	lhs = mul(lhs, k);
}

poly solve(int n, std::vector<std::vector<F2>> M) {
	poly f(n);
	int left_shift = 0;
	int sgn = 1;
	auto swap_row = [&](int i, int j) {
		if (i != j) {
			for (int k = 0; k < n; ++k)
				std::swap(M[i][k], M[j][k]);
			sgn = dec(0, sgn);
		}
	};
	auto swap_col = [&](int i, int j) {
		if (i != j) {
			for (int k = 0; k < n; ++k)
				std::swap(M[k][i], M[k][j]);
			sgn = dec(0, sgn);
		}
	};
	auto multiply_row = [&](int i) {
		for (int k = 0; k < n; ++k) {
			assert(M[i][k].b == 0);
			M[i][k].b = M[i][k].a;
			M[i][k].a = 0;
		}
		++left_shift;
	};
	// M[i][*] += M[j][*] * t
	auto add_row = [&](int i, int j, int t) {
		for (int k = 0; k < n; ++k) {
			auto z = mul(M[j][k], t);
			upd(M[i][k], mul(M[j][k], t));
		}
	};
	auto debug = [&]() {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				printf("(%d+%dz) ", M[i][j].a, M[i][j].b);
			}
			putchar('\n');
		}
	};
	for (int i = 0; i < n; ++i) {
		for (int t = 0; t < i; ++t)
			assert(M[i][t].b == 0);
		int j = -1;
		for (int t = i; t < n; ++t)
			if (M[i][t].b != 0) {
				j = t;
				break;
			}
		while (j == -1) {
			multiply_row(i);
			for (int t = 0; t < i; ++t) {
				if (M[i][t].b != 0) {
					assert(M[t][t].b != 0);
					int k = mul(M[i][t].b, fastpow(M[t][t].b, mod - 2));
					add_row(i, t, dec(0, k));
					assert(M[i][t].b == 0);
				}
			}
			for (int t = i; t < n; ++t) {
				if (M[i][t].b != 0) {
					j = t;
					break;
				}
			}
			if (left_shift > n) return f;
		}
		if (i != j) swap_col(i, j);
		for (int t = 0; t < i; ++t)
			assert(M[i][t].b == 0);
		for (int j = 0; j < n; ++j) if (i != j && M[j][i].b != 0) {
			int t = mul(fastpow(M[i][i].b, mod - 2), M[j][i].b);
			add_row(j, i, dec(0, t));
			assert(M[j][i].b == 0);
		}
	}
	for (int i = 0; i < n; ++i) {
		assert(M[i][i].b != 0);
		pud(sgn, M[i][i].b);
		int t = fastpow(M[i][i].b, mod - 2);
		for (int j = 0; j < n; ++j)
			pud(M[i][j], t);
		assert(M[i][i].b == 1);
	}	
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			if (i != j)
				assert(M[i][j].b == 0);
			else assert(M[i][j].b == 1);
	std::vector<std::vector<int>> a(n, std::vector<int>(n));
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) {
			a[i][j] = M[i][j].a;
		}
	f = solve(n, a);
	poly g(n + 1);
	for (int i = 0; i <= n; ++i) {
		pud(f[i], sgn);
	}
	for (int i = 0; i + left_shift <= n; ++i) {
		if (i + left_shift <= n) {
			g[i] = f[i + left_shift];
		}
	}
	return g;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	int n;
	std::cin >> n;
	std::vector<std::vector<F2>> M(n, std::vector<F2>(n));
	for (int i = 0; i < n; ++i) {
		std::string s;
		std::cin >> s;
		for (int j = 0; j < n; ++j) {
			if (s[j] == '1') {
				M[i][j].b = 1;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		std::string s;
		std::cin >> s;
		for (int j = 0; j < n; ++j) {
			if (s[j] == '1') {
				M[i][j].a = 1;
			}
		}
	}
	auto poly = solve(n, M);
	for (int i = 0; i <= n; ++i) {
		printf("%d\n", poly[i]);
	}
}


详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3664kb

input:

2
11
10
00
11

output:

0
0
1

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 3ms
memory: 3792kb

input:

10
0100110000
0000010111
0111000111
1000101100
1101000001
1111110000
1001001110
0000000011
0001000010
0100100110
1100010101
0001000001
0001001010
0011100111
0010101111
1001011011
1001100111
0111101001
0010100010
0001111011

output:

0
0
0
1
1
1
1
1
0
0
1

result:

ok 11 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

18
001100000000010111
011100011110001011
001101000001111111
000010010011100000
000011000100001001
001001101100010101
000100000100010010
100011100111001010
111110010110111001
100111011110100100
101000100001111011
110000100101011111
101011001000000111
110001011110010101
110010011111001110
001001011100...

output:

0
0
0
1
0
0
0
1
1
1
1
1
1
1
0
0
0
0
0

result:

ok 19 tokens

Test #4:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

18
110000000001011101
110001111000101100
110100000111111100
001001001110000000
001100010000100100
100110110001010100
010000010001001010
001110011100101011
111001011011100110
011101111010010010
100010000111101111
000010010101111110
101100100000011111
000101111001010111
001001111100111000
100101110010...

output:

0
0
0
0
1
0
1
1
1
0
1
1
0
0
1
0
1
1
0

result:

ok 19 tokens

Test #5:

score: 0
Accepted
time: 85ms
memory: 6324kb

input:

300
00000000010111011100011110001011001101000001111111000010010011100000000011000100001001001001101100010101000100000100010010100011100111001010111110010110111001100111011110100100101000100001111011110000100101011111101011001000000111110001011110010101110010011111001110001001011100100010010000000000...

output:

0
0
0
0
0
1
1
1
0
1
1
1
0
0
0
1
1
0
1
0
0
1
1
0
0
0
0
1
0
0
0
1
1
0
1
0
1
0
1
0
1
1
1
0
0
1
0
0
1
1
1
1
0
0
0
1
1
0
1
1
1
0
0
1
1
1
1
0
1
1
0
0
1
0
1
1
0
0
1
1
1
1
1
0
0
1
0
0
1
1
0
1
0
1
0
0
1
0
0
1
1
1
1
1
0
1
1
0
0
1
1
0
0
1
1
0
1
1
1
1
0
1
0
0
0
0
1
1
0
0
0
0
1
0
0
1
1
0
1
1
1
0
1
1
0
0
1
0
1
1
...

result:

ok 301 tokens

Test #6:

score: 0
Accepted
time: 88ms
memory: 6260kb

input:

300
00000001011101110001111000101100110100000111111100001001001110000000001100010000100100100110110001010100010000010001001010001110011100101011111001011011100110011101111010010010100010000111101111000010010101111110101100100000011111000101111001010111001001111100111000100101110010001001000000000001...

output:

0
0
0
1
0
1
1
0
0
0
0
1
1
1
0
0
1
0
0
0
0
1
0
1
1
1
1
1
0
0
1
1
0
1
1
1
1
0
1
0
1
1
1
1
1
1
0
0
1
1
0
1
0
1
0
0
1
0
0
1
0
0
0
1
0
1
1
0
1
1
0
1
1
1
0
0
0
1
0
1
0
1
1
0
1
1
0
1
1
1
1
1
1
0
1
0
0
1
0
0
1
0
1
0
0
0
0
1
1
0
1
1
0
0
0
1
1
1
0
1
1
0
1
0
1
0
0
1
1
1
0
0
1
0
1
0
0
1
0
1
1
1
1
0
1
1
0
1
0
1
...

result:

ok 301 tokens

Test #7:

score: 0
Accepted
time: 82ms
memory: 6372kb

input:

300
00000101110111000111100010110011010000011111110000100100111000000000110001000010010010011011000101010001000001000100101000111001110010101111100101101110011001110111101001001010001000011110111100001001010111111010110010000001111100010111100101011100100111110011100010010111001000100100000000000111...

output:

0
0
0
0
0
1
1
1
1
0
0
0
1
1
1
0
1
0
0
1
0
1
1
0
1
0
1
0
0
1
1
0
0
0
0
0
1
1
0
0
0
0
1
0
1
1
1
1
1
1
1
0
1
0
0
1
0
0
1
1
0
1
1
1
0
1
0
1
0
1
0
1
0
1
0
0
0
1
0
0
1
1
1
0
0
0
0
0
0
1
0
0
0
0
1
1
1
1
0
0
0
0
1
0
1
1
0
1
0
1
0
1
0
0
0
0
1
0
1
1
1
0
0
0
0
1
1
0
1
1
1
0
1
1
0
0
1
1
1
0
0
0
1
0
0
1
0
1
1
1
...

result:

ok 301 tokens

Test #8:

score: 0
Accepted
time: 19ms
memory: 4904kb

input:

200
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 201 tokens

Test #9:

score: 0
Accepted
time: 27ms
memory: 5348kb

input:

230
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
1
0
0
1
0
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 231 tokens

Test #10:

score: 0
Accepted
time: 35ms
memory: 5800kb

input:

270
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000...

output:

0
0
0
1
1
1
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 271 tokens

Test #11:

score: 0
Accepted
time: 49ms
memory: 6288kb

input:

300
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
1
0
0
0
1
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 301 tokens

Test #12:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

50
11000111100010110011010000011111110000100100111000
00000011000100001001001001101100010101000100000100
01001010001110011100101011111001011011100110011101
11101001001010001000011110111100001001010111111010
11001000000111110001011110010101110010011111001110
001001011100100010010000000000011101110101...

output:

0
1
1
1
0
0
0
0
0
0
1
0
0
1
1
1
0
1
0
0
0
1
0
0
0
1
1
1
0
0
1
1
0
0
1
0
1
0
0
1
0
1
0
1
1
1
1
0
0
1
1

result:

ok 51 tokens

Test #13:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

80
00011110001011001101000001111111000010010011100000000011000100001001001001101100
01010100010000010001001010001110011100101011111001011011100110011101111010010010
10001000011110111100001001010111111010110010000001111100010111100101011100100111
110011100010010111001000100100000000000111011101011011...

output:

0
1
0
0
1
0
1
0
1
0
0
1
1
0
0
0
0
1
1
0
0
0
1
1
1
0
1
1
1
0
0
0
1
1
1
0
0
0
0
1
1
0
0
1
0
1
0
1
0
0
1
0
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
0
0
0
0
0
1
0
0
1
0
1
1
0
0

result:

ok 81 tokens

Test #14:

score: 0
Accepted
time: 9ms
memory: 4116kb

input:

120
011110001011001101000001111111000010010011100000000011000100001001001001101100010101000100000100010010100011100111001010
111110010110111001100111011110100100101000100001111011110000100101011111101011001000000111110001011110010101110010011111
001110001001011100100010010000000000011101110101101110...

output:

0
1
0
0
1
0
1
0
0
1
1
0
0
0
1
1
0
1
0
0
0
0
0
1
1
1
0
1
0
0
0
0
1
1
0
1
1
0
0
1
1
1
0
1
1
1
0
0
0
1
0
1
0
1
1
1
1
1
0
1
0
0
1
0
1
1
0
1
0
1
1
0
1
1
1
1
1
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
1
0
1
1
1
0
1
0
1
0
1
0
0
0
1
0
1
0
0
1
0
0
0
0

result:

ok 121 tokens

Test #15:

score: 0
Accepted
time: 23ms
memory: 4572kb

input:

180
111000101100110100000111111100001001001110000000001100010000100100100110110001010100010000010001001010001110011100101011111001011011100110011101111010010010100010000111101111000010
0101011111101011001000000111110001011110010101110010011111001110001001011100100010010000000000011101110101101110100...

output:

0
1
0
0
1
1
1
1
0
1
1
0
1
0
0
0
1
1
0
0
0
0
0
1
1
1
0
0
1
1
0
0
0
1
1
1
1
0
1
1
1
0
0
1
1
0
1
1
1
0
0
0
1
0
0
1
0
1
0
1
1
1
0
0
0
1
0
1
1
1
1
0
0
0
0
0
1
1
1
0
0
1
1
1
1
1
0
0
0
0
0
0
1
1
0
1
0
1
1
0
0
1
1
1
1
0
0
0
1
0
1
0
1
1
0
1
0
1
0
0
1
1
1
1
0
1
1
1
1
0
0
1
0
1
1
1
0
1
1
0
1
1
1
1
1
0
0
0
1
1
...

result:

ok 181 tokens

Test #16:

score: 0
Accepted
time: 32ms
memory: 5144kb

input:

220
1000101100110100000111111100001001001110000000001100010000100100100110110001010100010000010001001010001110011100101011111001011011100110011101111010010010100010000111101111000010010101111110101100100000011111000101111001
010111001001111100111000100101110010001001000000000001110111010110111010011...

output:

1
0
0
0
0
0
1
1
0
1
0
0
0
1
1
1
1
1
1
0
1
1
0
0
1
1
1
0
0
0
0
0
0
1
1
1
0
1
0
1
0
1
1
0
0
1
0
1
0
1
1
0
0
1
1
0
1
1
1
0
1
1
0
1
1
1
1
0
0
0
1
0
1
1
1
1
0
0
0
1
0
1
1
0
1
1
1
1
1
0
0
0
0
1
1
0
0
0
0
0
1
0
0
0
0
1
0
0
0
1
1
1
1
1
0
0
1
1
0
0
0
0
0
1
1
1
0
0
0
1
1
0
1
1
1
1
1
1
1
0
1
0
1
0
0
1
1
0
1
0
...

result:

ok 221 tokens

Test #17:

score: 0
Accepted
time: 48ms
memory: 5544kb

input:

250
0010110011010000011111110000100100111000000000110001000010010010011011000101010001000001000100101000111001110010101111100101101110011001110111101001001010001000011110111100001001010111111010110010000001111100010111100101011100100111110011100010010111
001000100100000000000111011101011011101001111...

output:

0
1
1
1
0
1
1
0
0
1
1
0
1
0
0
0
1
0
0
1
1
0
0
1
1
1
0
1
0
0
0
0
1
0
0
0
0
1
1
1
1
0
0
1
0
1
1
1
1
1
0
1
1
0
1
0
0
0
1
0
0
0
0
0
1
0
1
1
0
1
1
0
0
1
1
1
0
1
0
0
1
0
0
1
0
1
0
0
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
0
1
0
1
1
1
0
0
1
0
0
0
1
1
0
1
1
1
1
0
1
1
0
0
1
1
0
1
1
1
1
0
0
0
0
1
1
1
0
1
1
0
1
0
...

result:

ok 251 tokens

Test #18:

score: 0
Accepted
time: 62ms
memory: 5704kb

input:

270
101100110100000111111100001001001110000000001100010000100100100110110001010100010000010001001010001110011100101011111001011011100110011101111010010010100010000111101111000010010101111110101100100000011111000101111001010111001001111100111000100101110010001001000000000001
1101110101101110100111111...

output:

0
1
0
0
1
1
1
0
0
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
1
1
0
1
1
0
0
0
1
0
0
1
1
1
0
0
0
0
1
0
0
0
0
0
1
1
1
0
1
1
1
0
0
1
1
0
1
1
1
1
0
1
1
0
0
1
0
0
0
1
1
0
0
1
1
1
1
0
1
0
0
1
0
1
0
0
1
1
1
1
0
0
0
1
0
1
0
0
1
0
0
0
1
1
0
0
1
1
0
1
1
1
1
0
1
1
0
0
0
0
1
0
0
1
1
0
0
0
0
0
0
1
1
0
0
1
0
1
1
0
0
0
0
1
0
0
...

result:

ok 271 tokens

Test #19:

score: 0
Accepted
time: 79ms
memory: 6168kb

input:

300
11001101000001111111000010010011100000000011000100001001001001101100010101000100000100010010100011100111001010111110010110111001100111011110100100101000100001111011110000100101011111101011001000000111110001011110010101110010011111001110001001011100100010010000000000011101110101101110100111111110...

output:

0
0
0
0
1
0
1
0
0
1
1
1
1
0
0
1
1
0
1
1
0
0
0
1
1
0
0
1
0
0
1
1
0
1
0
0
1
0
0
1
1
1
0
0
0
1
1
1
1
1
1
1
0
0
1
0
0
1
0
1
0
0
1
0
1
1
0
1
0
1
1
0
0
0
0
1
1
1
0
0
1
0
1
1
0
1
1
0
1
1
0
1
0
1
1
1
1
0
0
1
1
1
1
1
1
1
1
1
0
1
0
0
1
0
1
0
1
0
1
1
1
1
0
0
1
1
0
1
0
1
1
1
0
1
0
1
1
1
1
0
1
1
1
1
1
0
1
1
0
1
...

result:

ok 301 tokens

Test #20:

score: 0
Accepted
time: 82ms
memory: 6288kb

input:

300
00110100000111111100001001001110000000001100010000100100100110110001010100010000010001001010001110011100101011111001011011100110011101111010010010100010000111101111000010010101111110101100100000011111000101111001010111001001111100111000100101110010001001000000000001110111010110111010011111111010...

output:

1
1
0
1
1
0
1
1
1
1
1
1
1
0
0
1
0
1
0
1
0
0
1
1
0
0
1
0
0
0
0
0
1
0
0
1
1
1
0
0
0
1
1
0
0
1
0
1
0
1
0
1
0
0
0
1
0
0
1
0
0
0
0
0
0
0
1
0
1
1
0
0
1
0
0
1
0
0
1
1
1
0
0
0
1
1
0
1
0
1
0
0
0
0
0
0
0
1
0
0
1
1
1
1
0
1
0
0
0
1
0
1
0
1
1
0
0
0
1
1
0
1
1
0
0
0
0
1
0
1
0
1
0
0
0
0
0
1
1
0
0
0
0
1
0
0
0
0
0
0
...

result:

ok 301 tokens

Test #21:

score: 0
Accepted
time: 86ms
memory: 6284kb

input:

300
11010000011111110000100100111000000000110001000010010010011011000101010001000001000100101000111001110010101111100101101110011001110111101001001010001000011110111100001001010111111010110010000001111100010111100101011100100111110011100010010111001000100100000000000111011101011011101001111111101001...

output:

0
1
0
1
0
1
1
0
1
1
0
0
0
0
1
1
1
0
1
1
0
0
1
1
0
0
0
1
0
0
0
1
1
0
1
1
1
0
1
1
1
1
1
0
0
0
1
1
0
0
0
0
0
0
1
1
0
1
0
1
1
0
0
0
1
1
1
0
0
1
0
0
1
0
0
1
1
0
0
1
0
0
0
1
0
1
1
0
0
1
0
1
0
0
0
1
1
0
1
0
1
0
0
1
0
1
1
1
1
1
0
0
0
0
0
0
0
1
0
1
0
1
0
1
1
0
0
1
0
0
1
0
0
1
0
1
1
0
0
1
0
0
1
0
1
0
0
1
0
0
...

result:

ok 301 tokens