#include #include #include #include constexpr int MAX_N = 24; constexpr int HALF = MAX_N / 2; int res[1 << (MAX_N - 1)][HALF]; int f[1 << MAX_N]{}; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, k; std::cin >> n >> m >> k; std::vector S(m); for (int i = 0; i < m; ++i) { std::string s; std::cin >> s; for (int j = 0; j < n; ++j) { S[i] |= (s[j] - '0') << j; } } if (k <= HALF) { /* [1,1] [1,x] */ for (int i = 0; i < 1 << n; ++i) { f[i] = m; } for (int topbit : { 0, 1 }) { for (int i = 0; i < 1 << (MAX_N - 1); ++i) for (int j = 0; j < HALF; ++j) res[i][j] = 0; for (const int s : S) if ((s >> (n - 1)) == topbit) ++res[s & ~(1 << (n - 1))][0]; for (int B = 1; B < 1 << (n - 1); B <<= 1) { for (int L = 0; L < 1 << (n - 1); L += 2 * B) { for (int p = 0; p < B; ++p) { int* u = res[L + p], * v = res[L + B + p]; for (int t = k; t--;) { int tmp = u[t]; u[t] = tmp + v[t]; v[t] = tmp + (t ? v[t - 1] : 0); } } } } for (int T = 0; T < 1 << n; ++T) { int x = (T >> (n - 1)) == 1 and topbit == 1; for (int i = 0; i < k - x; ++i) { f[T] -= res[T & ~(1 << (n - 1))][i]; } } } std::vector g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); g[f[T]] = std::min(g[f[T]], T_size); } for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]); for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n'; } else { const int r = n - k + 1; /* [x,x] [x,1] */ for (int topbit : { 0, 1 }) { for (int i = 0; i < 1 << (MAX_N - 1); ++i) for (int j = 0; j < HALF; ++j) res[i][j] = 0; for (const int s : S) if ((s >> (n - 1)) == topbit) ++res[s & ~(1 << (n - 1))][0]; for (int B = 1; B < 1 << (n - 1); B <<= 1) { for (int L = 0; L < 1 << (n - 1); L += 2 * B) { for (int p = 0; p < B; ++p) { int* u = res[L + p], * v = res[L + B + p]; for (int t = r; t-- > 1;) { u[t] = u[t - 1] + v[t - 1]; v[t] += u[t - 1]; } u[0] = 0; } } } for (int T = 0; T < 1 << n; ++T) { int x = (T >> (n - 1)) == 0 or topbit == 0; for (int i = 0; i < r - x; ++i) { f[T] += res[T & ~(1 << (n - 1))][i]; } } } std::vector g(m + 1, n); for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); g[f[T]] = std::min(g[f[T]], T_size); } for (int i = m - 1; i >= 0; --i) g[i] = std::min(g[i], g[i + 1]); for (int i = 1; i <= m; ++i) std::cout << g[i] << '\n'; } }