#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include using Poly = std::array; Poly operator+(const Poly& x, const Poly& y) { Poly z; for (std::size_t i = 0; i < 63; ++i) { z[i] = x[i] + y[i]; } return z; } Poly operator-(const Poly& x, const Poly& y) { Poly z; for (std::size_t i = 0; i < 63; ++i) { z[i] = x[i] - y[i]; } return z; } Poly operator*(const Poly& x, const Poly& y) { std::array dat{}; for (std::size_t i = 0; i < 32; ++i) for (std::size_t j = 0; j < 32; ++j) { dat[i + j] += int64_t(x[i]) * int64_t(y[j]); } return dat; } void unit_walsh_hadamard_transform(Poly& x0, Poly& x1) { Poly y0 = x0, y1 = x1; x0 = y0 + y1; // 1, 1 x1 = y0 - y1; // 1, -1 } template void unit_transform(UnitTransform transform, ReferenceGetter ref_getter, std::index_sequence) { transform(ref_getter(Seq)...); } void walsh_hadamard(std::vector& x) { const std::size_t n = x.size(); for (std::size_t block = 1; block < n; block *= 2) { for (std::size_t l = 0; l < n; l += 2 * block) { for (std::size_t offset = l; offset < l + block; ++offset) { const auto ref_getter = [&](std::size_t i) -> Poly& { return x[offset + i * block]; }; unit_transform(unit_walsh_hadamard_transform, ref_getter, std::make_index_sequence<2>()); } } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::size_t n; std::cin >> n; std::vector a(1 << n, Poly{}), b(1 << n, Poly{}), c(1 << n, Poly{}); for (std::size_t i = 0; i < 1U << n; ++i) { for (std::size_t j = 0; j < 32; ++j) { std::cin >> a[i][j]; } } for (std::size_t i = 0; i < 1U << n; ++i) { for (std::size_t j = 0; j < 32; ++j) { std::cin >> b[i][j]; } } walsh_hadamard(a); walsh_hadamard(b); for (std::size_t i = 0; i < 1U << n; ++i) c[i] = a[i] * b[i]; walsh_hadamard(c); for (std::size_t i = 0; i < 1U << n; ++i) { for (std::size_t j = 0; j < 63; ++j) { std::cout << ((c[i][j] >> n) & 1) << ' '; } std::cout << '\n'; } return 0; }