#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false
const int MAXN = 300 * 1000 + 17;
const int MAXM = 20;
int ile[1 << MAXM];
int suma[MAXM];
int wyn[1 << MAXM];
int a[MAXN];
int n, m;
void brut () {
    for (int i = 0; i < n; i ++) {
        int x = a[i];
        for (int j = 0; j < m; j ++) {
            if (x % 2 == 1) {
                suma[j] --;
            }
            x /= 2;
        }
        for (int j = 0; j < n; j ++) {
            if ((i != j && ile[a[j]] >= 1) || (ile[a[j]] >= 2)) {
                int y = a[j];
                int akt = 0;
                for (int k = 0; k < m; k ++) {
                    int c = suma[k];
                    if (y % 2 == 1) {
                        c --;
                    }
                    if (c >= n/2) {
                        akt ++;
                    }
                    y /= 2;
                }
                wyn[i] = max(wyn[i], akt);
            }
        }
        x = a[i];
        for (int j = 0; j < m; j ++) {
            if (x % 2 == 1) {
                suma[j] ++;
            }
            x /= 2;
        }
    }
    for (int i = 0; i < n; i ++) {
        cout << wyn[i] << "\n";
    }
}
int main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i ++) {
        int x = 0, y;
        for (int j = 0; j < m; j ++) {
            cin >> y;
            x += (y * (1 << j));
            if (y) {
                suma[j] ++;
            }
        }
        a[i] = x;
        ile[x] ++;
    }
    if (n <= 3 * 1000) {
        brut();
        return 0;
    }
    for (int i = 0; i < (1 << m); i ++) {
        int x = i;
        for (int j = 0; j < m; j ++) {
            if (x % 2 == 1) {
                suma[j] --;
            }
            x /= 2;
        }
        for (int j = 0; j < (1 << m); j ++) {
            if ((i != j && ile[j] >= 1) || (ile[j] >= 2)) {
                int y = j;
                int akt = 0;
                for (int k = 0; k < m; k ++) {
                    int c = suma[k];
                    if (y % 2 == 1) {
                        c --;
                    }
                    if (c >= n/2) {
                        akt ++;
                    }
                    y /= 2;
                }
                wyn[i] = max(wyn[i], akt);
            }
        }
        x = i;
        for (int j = 0; j < m; j ++) {
            if (x % 2 == 1) {
                suma[j] ++;
            }
            x /= 2;
        }
    }
    for (int i = 0; i < n; i ++) {
        cout << wyn[a[i]] << "\n";
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |