#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using ll = long long;
#define debug(x) #x << " = " << x << '\n'
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> vote(n + 1, std::vector<int>(m, 0));
  std::vector<int> accept(m, 0);
  
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      std::cin >> vote[i][j];
      accept[j] += vote[i][j];
    }
  }
  std::vector<int> cnt((1 << m), 0);
  std::vector<int> one((1 << m), 0);
  for (int mask = 0; mask < (1 << m); mask++) {
    for (int i = 1; i <= n; i++) {
      bool ok = true;
      for (int j = 0; j < m; j++) {
        if ((mask >> j & 1) && vote[i][j]) {
          ok = false;
          break;
        }
      }      
      if (ok) {
        cnt[mask]++;
        one[mask] = i;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    std::vector<int> care;
    int yes = 0;
    for (int j = 0; j < m; j++) {
      int sz = accept[j] - vote[i][j];
      if (sz == n / 2) {
        care.push_back(j);
      } else if (sz > n / 2) {
        yes++;
      }
    } 
    // vr sa aleg cat mai multe din care a.i. intersectia e nevida si diferita de {i}
    int answer = 0;
    for (int mask = 0; mask < (1 << (int) care.size()); mask++) {
      int realmask = 0;
      for (int i = 0; i < (int) care.size(); i++) {
        if (mask >> i & 1) {
          realmask |= 1 << care[i];
        }
      }  
      if (cnt[realmask] >= 2 || (cnt[realmask] == 1 && one[realmask] != i)) {
        answer = std::max(answer, __builtin_popcount(mask));
      }
    }
    std::cout << answer + yes << ' ';
  }
  
  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... |