#pragma GCC target("pclmul", "sse2", "sse4.1") #include #include #include __int64_t clmul(__int64_t x, __int64_t y) { __m128i x_ = _mm_set_epi64x(0, x); __m128i y_ = _mm_set_epi64x(0, y); __m128i z_ = _mm_clmulepi64_si128(x_, y_, 0); return _mm_extract_epi64(z_, 0); } #include #include #include using i64 = __int64_t; static constexpr int n_max = 18; using poly = std::array; static constexpr int W = 31; template void bitwise_transform(F f, std::vector &a) { const int n = a.size(); for (int w = 1; w < n; w *= 2) { for (int k = 0; k < n; k += w * 2) { for (int i = 0; i < w; i++) { f(a[k + i], a[k + w + i]); } } } } std::vector rank(const std::vector &a) { const int n = a.size(); std::vector b(n); for (int i = 0; i < n; i++) { int cnt = 0; for (int k = 0; k < n_max; k++) { if (i >> k & 1) { cnt++; } } b[i][cnt] = a[i]; } return b; } std::vector unrank(const std::vector &a) { const int n = a.size(); std::vector b(n); for (int i = 0; i < n; i++) { int cnt = 0; for (int k = 0; k < n_max; k++) { if (i >> k & 1) { cnt++; } } b[i] = a[i][cnt]; } return b; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector A(1 << n, 0), B(1 << n, 0); for (i64 &e : A) { for (int i = 0; i <= W; i++) { int a; std::cin >> a; e |= i64(a) << i; } } for (i64 &e : B) { for (int i = 0; i <= W; i++) { int b; std::cin >> b; e |= i64(b) << i; } } const auto add_sub = [](i64 &l, i64 &r) { l ^= r; }; const auto addp_sup = [](auto &l, auto &r) { for (int i = 0; i <= n_max; i++) { r[i] ^= l[i]; } }; bitwise_transform(add_sub, A); bitwise_transform(add_sub, B); auto rA = rank(A); auto rB = rank(B); bitwise_transform(addp_sup, rA); bitwise_transform(addp_sup, rB); std::vector rC(1 << n); for (int i = 0; i < (1 << n); i++) { for (int j = 0; j <= n_max; j++) { for (int k = 0; k <= n_max - j; k++) { rC[i][j + k] ^= clmul(rA[i][j], rB[i][k]); } } } bitwise_transform(addp_sup, rC); auto c = unrank(rC); bitwise_transform(add_sub, c); for (const i64 &e : c) { for (int i = 0; i <= W * 2; i++) { std::cout << (e >> i & 1) << " \n"[i == W * 2]; } } return 0; }