#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #define MAX_N 24 #define HALF MAX_N / 2 int res[1 << (MAX_N - 1)][HALF]; int f[1 << MAX_N] = {}; int S[300000] = {}; char buf[MAX_N + 1]; int G[300001] = {}; int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < m; ++i) { scanf("%s", buf); for (int j = 0; j < n; ++j) { S[i] |= (buf[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; topbit < 2; ++topbit) { for (int i = 0; i < 1 << (MAX_N - 1); ++i) for (int j = 0; j < HALF; ++j) res[i][j] = 0; for (int i = 0; i < m; ++i) if ((S[i] >> (n - 1)) == topbit) ++res[S[i] & ~(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 && topbit == 1; for (int i = 0; i < k - x; ++i) { f[T] -= res[T & ~(1 << (n - 1))][i]; } } } } else { const int r = n - k + 1; /* [x,x] [x,1] */ for (int topbit = 0; topbit < 2; ++topbit) { for (int i = 0; i < 1 << (MAX_N - 1); ++i) for (int j = 0; j < HALF; ++j) res[i][j] = 0; for (int i = 0; i < m; ++i) if ((S[i] >> (n - 1)) == topbit) ++res[S[i] & ~(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 || topbit == 0; for (int i = 0; i < r - x; ++i) { f[T] += res[T & ~(1 << (n - 1))][i]; } } } } for (int i = 0; i <= m; ++i) { G[i] = n; } for (int T = 0; T < 1 << n; ++T) { int T_size = __builtin_popcount(T); if (T_size < G[f[T]]) { G[f[T]] = T_size; } } for (int i = m - 1; i >= 0; --i) { if (G[i + 1] < G[i]) G[i] = G[i + 1]; } for (int i = 1; i <= m; ++i) printf("%d\n", G[i]); }