Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int ans;
ll bits = (ll)((1<<31)-1);
void dfs(int depth,string str[],int m,int bit,int cnt){
  if(depth==m){
    int num[555/m+1]={};
    for(int i=0;i<m;i++){
      if(bit&(i<<m)){
	for(int j=0;j<str[i].size();j++){
	  if(str[i][j]=='1')
	    num[j]++;
	}
      }
    }
    for(int i=0;i<555/m+1;i++){
      if(num[i]%2)return;
    }
    ans=max(ans,cnt);
    return;
  }
  dfs(depth+1,str,m,bit+(1<<depth),cnt+1);
  dfs(depth+1,str,m,bit,cnt);
}
void dfs2(int depth,int bit,int cnt,int bitn[],int m){
  //cout<<"!"<<endl;
  if(depth==m){
    if((bit&bits)==0)
      ans=max(ans,cnt);
    return;
  }
  dfs2(depth+1,bit^bitn[depth],cnt+1,bitn,m);
  dfs2(depth+1,bit,cnt,bitn,m);
}

void dfs4(int depth,int bit,int cnt,int bitn[],int m,int n){
  //cout<<"!"<<endl;
  if(depth==m){
    int cntt=0;
    for(int i=0;i<n;i++){
      if(bit&(1<<i)){
	cntt++;
      }
    }
    ans=max(ans,n-cntt);
    return;
  }
  dfs2(depth+1,bit^bitn[depth],cnt+1,bitn,m);
  dfs2(depth+1,bit,cnt,bitn,m);
}

void dfs3(int depth,string str[],int m,int bit,int cnt,int n){
  if(depth==m){
    int num[555/m+1]={};
    for(int i=0;i<m;i++){
      if(bit&(i<<m)){
	for(int j=0;j<str[i].size();j++){
	  if(str[i][j]=='1')
	    num[j]++;
	}
      }
    }
    int cntt=0;
    for(int i=0;i<555/m+1;i++){
      if(num[i]%2)cntt++;
    }
    ans=max(ans,n-cntt);
    return;
  }
  dfs3(depth+1,str,m,bit+(1<<depth),cnt+1);
  dfs3(depth+1,str,m,bit,cnt);
}

int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    ans=0;
    string str[n];
    for(int i=0;i<n;i++){
      cin>>str[i];
    }
   if(m==1){
     cout<<(n/2)*2<<endl;
      continue;
   }else if(n==1){
     cout<<0<<endl;
     continue;
   }
   string str2[m];
   if(n>m){
     for(int i=0;i<m;i++){
       string s="";
       for(int j=0;j<n;j++){
	 s+=str[j][i];
       }
       str2[i]=s;
     }
   }
   if(max(n,m)>30){
     if(n>m){
       dfs3(0,str2,m,0,0,n);
	cout<<ans<<endl;
     }else{
       dfs(0,str,n,0,0);
       cout<<ans<<endl;
     }
     continue;
   }else{
     if(n>m){
       int bitm[m+10]={};
       for(int i=0;i<m;i++){
	 for(int j=0;j<n;j++){
	   bitm[i]+=(str2[i][j]-'0')*(1<<j);
	 }
       }
       dfs4(0,0,0,bitm,m,n);
     }else{
       int bitn[n+10]={};
	for(int i=0;i<n;i++){
	  for(int j=0;j<m;j++){
	    bitn[i]+=(str[i][j]-'0')*(1<<j);
	  }
	}
	dfs2(0,0,0,bitn,n);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Compiler output:
a.cc:13:23: warning: integer overflow in expression of type 'int' results in '2147483647' [-Woverflow]
   13 | ll bits = (ll)((1<<31)-1);
      |                ~~~~~~~^~
a.cc: In function 'void dfs3(int, std::string*, int, int, int, int)':
a.cc:79:7: error: too few arguments to function 'void dfs3(int, std::string*, int, int, int, int)'
   79 |   dfs3(depth+1,str,m,bit+(1<<depth),cnt+1);
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:61:6: note: declared here
   61 | void dfs3(int depth,string str[],int m,int bit,int cnt,int n){
      |      ^~~~
a.cc:80:7: error: too few arguments to function 'void dfs3(int, std::string*, int, int, int, int)'
   80 |   dfs3(depth+1,str,m,bit,cnt);
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:61:6: note: declared here
   61 | void dfs3(int depth,string str[],int m,int bit,int cnt,int n){
      |      ^~~~