#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
using namespace std;
const int maxn = 3e5 + 10, maxm = 22;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int n, m;
int a[maxn][maxm], cnt[maxm];
vector < int > u[maxm];
int fix[maxn];
int main()
{
    speed();
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= m; ++ j)
        {
            cin >> a[i][j];
            cnt[j] += a[i][j];
            if(a[i][j])u[j].pb(i);
        }
    }
    for (int i = 1; i <= n; ++ i)
    {
        for (int p = 1; p <= n; ++ p)
            fix[p] = 0;
        int ans = 0;
        for (int j = 1; j <= m; ++ j)
        {
            if(cnt[j] - a[i][j] >= n/2)ans ++;
            if(cnt[j] - a[i][j] == n/2)
            {
                for (auto x: u[j])
                    fix[x] ++;
            }
        }
        int best = ans;
        for (int j = 1; j <= n; ++ j)
        {
            if(j == i)continue;
            best = min(best, fix[j]);
           // cout << fix[j] << " ";
        }
       // cout << endl;
        cout << ans - best << endl;
    }
    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... |