#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Yay!! #define endl codeforces // macros for iterator #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) // alias using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair; using tii = std::tuple; using pll = std::pair; using tll = std::tuple; template using vec = std::vector; template using vvec = vec>; // variadic min/max template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } // variadic chmin/chmax template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } // multi demension array template struct multi_dim_array { using type = std::array::type, Head>; }; template struct multi_dim_array { using type = std::array; }; template using mdarray = typename multi_dim_array::type; // fill container template void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } } // make multi dimension vector template vec make_v(ssize_t sz) { return vec(sz); } template auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v(std::forward(ts)...)); return vec(hs, v); } // init namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } constexpr std::size_t SIZE = 200 * 200; using bs_type = std::bitset; using matrix_type = vec; std::pair gauss_elim(matrix_type mat) { ll upper_row = 0; ll rank = 0; for (ll col = 0; col < SIZE && upper_row < mat.size(); col++) { ll row = -1; for (ll r = upper_row; r < mat.size(); r++) { if (mat[r].test(col)) { row = r; break; } } if (row == -1) continue; rank++; std::swap(mat[upper_row], mat[row]); for (ll r = 0; r < mat.size(); r++) { if (r == upper_row) continue; if (!mat[r].test(col)) continue; mat[r] ^= mat[upper_row]; } upper_row++; } return std::make_pair(std::move(mat), rank); } int main() { ll n, m; std::cin >> n >> m; auto av = make_v(m, n); for (auto &&vs : av) for (auto &&s : vs) std::cin >> s; vec ans(m - 1); for (ll i = 0; i < m - 1; i++) ans[i] = std::string(m - i - 1, '0'); matrix_type op_mat(2 * n + 2 * (2 * n - 1)); for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) { ll idx = i * n + j; op_mat[i].set(idx, 1); op_mat[j + n].set(idx, 1); ll k1 = i + j; op_mat[k1 + 2 * n].set(idx, 1); ll k2 = i - j; k2 += n - 1; op_mat[k2 + 2 * n + 2 * n - 1].set(idx, 1); } { auto [ tmp, rank ] = gauss_elim(op_mat); op_mat = std::move(tmp); op_mat.erase(op_mat.begin() + rank, op_mat.end()); } for (ll i = 0; i < m; i++) for (ll j = i + 1; j < m; j++) { bs_type bs; for (ll r = 0; r < n; r++) for (ll c = 0; c < n; c++) if (av[i][r][c] != av[j][r][c]) bs.set(r * n + c, 1); auto cpy = op_mat; cpy.push_back(bs); auto [ ign, rank ] = gauss_elim(cpy); if (rank == op_mat.size()) ans[i][j - i - 1] = '1'; } for (auto &&s : ans) std::cout << s << "\n"; return 0; }