stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <iostream>

#include <cstdlib>

#include <cstring>

bool table[12][10005];

using namespace std;

int r,c;

int ans;

int ji(){

    int op=0;

    for(int j=1;j<=c;j++){

        int a=0,b=0;

        for(int i=1;i<=r;i++){

            if(table[i][j]) a++;

            else b++;

        }

        op+=(a>b?a:b);

    }

    return op;

}

void br(int now){

    if(now>r){

        int bi=ji();

        ans=ans>bi?ans:bi;

        return ;

    }

    br(now+1);

    for(int i=1;i<=c;i++)

        if(table[now][i]) table[now][i]=false;

        else table[now][i]=true;

    br(now+1);

    for(int i=1;i<=c;i++)

        if(table[now][i]) table[now][i]=false;

        else table[now][i]=true;

}

int main(void){

    while(cin>>r>>c){

        if(0==r&&0==c) break;

        memset(table,0,sizeof(table));

        ans=-1000000;

        for(int i=1;i<=r;i++)

            for(int j=1;j<=c;j++){

                cin>>table[i][j];

            }

        br(1);

        cout<<ans<<endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.138627282247989x):
#include<stdio.h>

#include<vector>

#include<queue>

#include<string.h>

#include<iostream>

#include<algorithm>

#include<cmath>

#include<set>

#define INF 1000000000

#define MAXN 100005

#define sf(n) scanf("%d",&n)

#define sff(m,n) scanf("%d%d",&m,&n)

#define gl(x) getline(cin,x)

#define gc() getchar()

using namespace std;

int a[15][10005];

int main()

{

    while(1){

    int n,m;sff(n,m);

    if(n==0&&m==0)break;

    for(int i=0;i<n;i++)

        for(int j=0;j<m;j++)

            sf(a[i][j]);

    int mmax=0;

    for(int i=0;i<pow(2,n);i++)

    {

        int b[10];int r=i;

        for(int j=0;j<n;j++)

        {

            b[j]=r%2;r/=2;

        }

        int sum=0;

        for(int j=0;j<m;j++)

        {

            int k=0;

            for(int u=0;u<n;u++){

                //cout<<a[u][j]<<"  "<<b[u]<<endl;

                if((a[u][j]&&!b[u])||((!a[u][j])&&b[u]))k++;

            }

            //cout<<k<<"??"<<endl;

            sum+=max(k,n-k);

        }

        //cout<<i<<"  "<<sum<<endl;

        mmax=max(mmax,sum);

    }

    printf("%d\n",mmax);

    }

}
// Slower C++ solution:
#include <algorithm>

#include <cstring>

#include <map>

#include <iostream>



using namespace std;



bool maps[12][10002];

bool row[12];

int ans=0x7fffffff;

int r,c;

int r_c;

map<string,bool>prow;



int dfs(int st)

{

    for(int i=st;i<r;++i)

    {

        if(row[i])continue;

        else

        {

            row[i]=true;

            string str1="0000000000",str2="0000000000";

            for(int j=0;j<r;++j)

            {

                str1[j]=row[j]+'0';

                str2[j]=!row[j]+'0';

            }

            if(prow.count(str1)||prow.count(str2));

            else

            {

                prow[str1]=true;

                prow[str2]=true;

                int sun=0;

                for(int j=0;j<c;++j)

                {

                    int s=0;

                    for(int k=0;k<r;++k)

                        s+=(maps[k][j]^row[k]);

                    sun+=min(s,r-s);

                    if(sun>ans)break;

                }

                ans=min(ans,sun);

            }

            dfs(st+1);

            row[i]=false;

        }

    }

    return 0;

}



int main()

{

    while(scanf("%d%d",&r,&c),r+c)

    {

        r_c=r*c;

        prow.clear();

        memset(maps,0,sizeof(maps));

        memset(row,0,sizeof(row));

        ans=0x7fffffff;

        for(int i=0;i<r;++i)

            for(int j=0;j<c;++j)

                scanf("%d",&maps[i][j]);

        dfs(0);

        printf("%d\n",r_c-ans);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.146064934327543x):
#include<stdio.h>

#include<vector>

#include<queue>

#include<string.h>

#include<iostream>

#include<algorithm>

#include<cmath>

#include<set>

#define INF 1000000000

#define MAXN 100005

#define sf(n) scanf("%d",&n)

#define sff(m,n) scanf("%d%d",&m,&n)

#define gl(x) getline(cin,x)

#define gc() getchar()

using namespace std;

int a[15][10005];

int main()

{

    while(1){

    int n,m;sff(n,m);

    if(n==0&&m==0)break;

    for(int i=0;i<n;i++)

        for(int j=0;j<m;j++)

            sf(a[i][j]);

    int mmax=0;

    for(int i=0;i<pow(2,n);i++)

    {

        int b[10];int r=i;

        for(int j=0;j<n;j++)

        {

            b[j]=r%2;r/=2;

        }

        int sum=0;

        for(int j=0;j<m;j++)

        {

            int k=0;

            for(int u=0;u<n;u++){

                //cout<<a[u][j]<<"  "<<b[u]<<endl;

                if((a[u][j]&&!b[u])||((!a[u][j])&&b[u]))k++;

            }

            //cout<<k<<"??"<<endl;

            sum+=max(k,n-k);

        }

        //cout<<i<<"  "<<sum<<endl;

        mmax=max(mmax,sum);

    }

    printf("%d\n",mmax);

    }

}
// Slower C++ solution:
#include<iostream>

#include<bitset>

#include<cmath>

using namespace std;

bitset<10000>a[10];

int main()

{

	int H,W,count,sum;

	while(cin>>H>>W,H)

	{

		int temp;

		for(int i=0;i<H;i++)

		{

			for(int j=0;j<W;j++)

			{

				cin>>temp;

				if(temp)a[i].set(j);

				else a[i].reset(j);

			}

		}

		sum=0;

		for(int cur=0;cur<(1<<H);cur++)

		{

			count=0;

			for(int i=0;i<H;i++)

			{

				if((cur>>i)&1)a[i].flip();

			}

			for(int j=0;j<W;j++)

			{

				temp=0;

				for(int i=0;i<H;i++)

				{

					if(a[i].test(j))temp++;

				}

				count+=max(temp,H-temp);

			}

			sum=max(count,sum);

			for(int i=0;i<H;i++)

			{

				if((cur>>i)&1)a[i].flip();

			}

		}

		cout<<sum<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.173846356433154x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cmath>

#include<cstring>

#include<cstdlib>

#include<iostream>

#include<algorithm>

#include<bitset>

#define MAX_C 10000

#define MAX_N 10

using namespace std;

bitset<MAX_C> b[MAX_N];

int main()

{

    int n,c;

    int ans,res;

    res=0;

    scanf("%d %d",&n,&c);

    while(n!=0||c!=0)

    {

    for(int i=0;i<n;i++)

        for(int j=0;j<c;j++)

        {

          bool x;

          cin>>x;

          b[i][j]=x;

        }

    for(int i=0;i<(1<<n);i++)

    {

        for(int j=0;j<n;j++)

            if(i&(1<<j))

              b[j].flip();

    int sum=0;

    for(int j=0;j<c;j++)

    {

        int cnt=0;

        for(int k=0;k<n;k++)

            if(b[k][j]) cnt++;

        ans=max(cnt,n-cnt);

        sum+=ans;

    }

    res=max(sum,res);

    for(int j=0;j<n;j++)

            if(i&(1<<j))

              b[j].flip();

    }

    printf("%d\n",res);

    scanf("%d %d",&n,&c);

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.178024473520327x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

using namespace std;

int n,m,ans;

int a[11][100001];

void dfs(int x)

{

	int i,j;

	if(x>=n)

	return;

	else

	{

		int sum=0;

		for(i=0;i<m;i++)

		{

			int count=0;

			for(j=0;j<n;j++)

			{

			  if(a[j][i]==1)

			  count++;	

			}

			

			sum+=max(count,n-count);

		}

		if(sum>ans)

		ans=sum;

		dfs(x+1);

		for(i=0;i<m;i++)

		{

			if(a[x][i]==1)

			a[x][i]=0;

			else

			a[x][i]=1;

		}

		dfs(x+1);

	   for(i=0;i<m;i++)

		{

			if(a[x][i]==1)

			a[x][i]=0;

			else

			a[x][i]=1;

		}

	}

}

int main()

{

	int i,j;

   while(~scanf("%d%d",&n,&m))

   {

   	if(n==0&&m==0)

   	break;

   	memset(a,0,sizeof(a));

   	ans=0;

   	for(i=0;i<n;i++)

   	{

   		for(j=0;j<m;j++)

   		{

   			scanf("%d",&a[i][j]);

		}

	}

	 dfs(0);

	 printf("%d\n",ans);

   }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 51.85695435010301x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

int f[15][10005];

int n,m;

int anss=0,ans=0;

void dfs(int q){

	if(q>n){

		//if(ans>anss)anss=ans;

		return ;

	}

	ans=0;

	for(int j=1;j<=m;j++){

		int count=0;

		for(int i=1;i<=n;i++){

			if(f[i][j]==0)count++;

		}//cout<<"count "<<count<<endl;

		if(count>n/2)ans+=count;

		else ans+=n-count;

	}

	//cout<<"ans "<<ans<<endl;

	if(ans>anss)anss=ans;//cout<<anss<<endl;

	dfs(q+1);

	//ans=0;

	for(int j=1;j<=m;j++){

		f[q][j]=(f[q][j]+1)%2;

	}



	dfs(q+1);

	for(int j=1;j<=m;j++){

		f[q][j]=(f[q][j]+1)%2;

	}

}

int main(){

	while(scanf("%d%d",&n,&m)&&!(n==0)){

		for(int i=1;i<=n;i++){

			for(int j=1;j<=m;j++){

				scanf("%d",&f[i][j]);

			}

		}

		dfs(1);

		cout<<anss<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.120318510625178x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



bitset<10000> maze[10];



int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    int r, c;

    while(cin >> r >> c, (r && c)){

        for(int i = 0; i < r; ++i)

            for(int j = 0; j < c; ++j){

                bool tmp;

                cin >> tmp;

                maze[i][j] = tmp;

            }

        int time = 1 << r;

        int ans = 0;

        for(int i = 0; i < time; ++i){

            for(int j = 0; j < r; ++j)

                if(i & (1 << j))

                    maze[j].flip();

            int result = 0;

            for(int C = 0; C < c; ++C){

                int cntpercol = 0;

                for(int R = 0; R < r; ++R)

                    if(maze[R][C])

                        ++cntpercol;

                result += max(cntpercol, r - cntpercol);

            }

            ans = max(ans, result);

            for(int j = 0; j < r; ++j)

                if(i & (1 << j))

                    maze[j].flip();

        }

        cout << ans << endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.215059766560873x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

using namespace std;

#define MAX_R 10

#define MAX_C 10000

int R,C;

int res;

int G[MAX_R + 1][MAX_C + 1];

int main(){

    while(cin >> R >> C){

        if(!(R || C)) break;

        for(int i = 0 ; i < R ; i++)

            for(int j = 0 ; j < C ; j++)

                cin >> G[i][j];

        int BIT_SIZE = 1 << R;

        res = 0;

        for(int j = 0 ; j < BIT_SIZE ; j++){

            int total = 0;

            for(int cc = 0 ; cc < C ; cc++){

                int k = j;

                int num0 = 0,num1 = 0;

                for(int rr = 0 ; rr < R ; rr++){

                    if(k & 1) G[rr][cc] ? num1++ : num0++;

                    else G[rr][cc] ? num0++ : num1++;

                    k >>= 1;

                }

                total += max(num0,num1);

            }

            res = max(res,total);

        }

        cout << res << endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.140168559358231x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <iostream>

#include <cstdlib>

#include <cstring>

bool table[12][10005];

using namespace std;

int r,c;

int ans;

int ji(){

    int op=0;

    for(int j=1;j<=c;j++){

        int a=0,b=0;

        for(int i=1;i<=r;i++){

            if(table[i][j]) a++;

            else b++;

        }

        op+=(a>b?a:b);

    }

    return op;

}

void br(int now){

    if(now>r){

        int bi=ji();

        ans=ans>bi?ans:bi;

        return ;

    }

    br(now+1);

    for(int i=1;i<=c;i++)

        if(table[now][i]) table[now][i]=false;

        else table[now][i]=true;

    br(now+1);

    for(int i=1;i<=c;i++)

        if(table[now][i]) table[now][i]=false;

        else table[now][i]=true;

}

int main(void){

    while(cin>>r>>c){

        if(0==r&&0==c) break;

        memset(table,0,sizeof(table));

        ans=-1000000;

        for(int i=1;i<=r;i++)

            for(int j=1;j<=c;j++){

                cin>>table[i][j];

            }

        br(1);

        cout<<ans<<endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.826524335290267x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<algorithm>

#include<cstring>

#include<iostream>

#include<bitset>



using namespace std;



const int MAXR = 15, MAXC = 10000+100;

int mapp[MAXR][MAXC];

int r, c;





int main()

{

    while(scanf("%d%d", &r, &c) == 2 && r && c)

    {

        for(int i=0; i<r; ++i)

        {

            for(int j=0; j<c; ++j)

            {

                scanf("%d", &mapp[i][j]);

            }

        }

        int ans = 0;

        bitset<32> bs;

        for(int i=0; i<r; i++) bs[i] = 1;

        int m = bs.to_ulong();

        for(unsigned int i=0; i<=m; i++)

        {

            bs = i;

            int cnt = 0;

            for(int j=0; j<c; j++)

            {

                int cnt1 = 0, cnt0 = 0;

                for(int k=0; k<r; k++)

                {

                    if(mapp[k][j] && bs[k]==0) cnt1++;

                    else if(!mapp[k][j] && bs[k]) cnt1++;

                    else cnt0++;

                }

                cnt+= max(cnt1, cnt0);

            }

            ans = max(ans, cnt);

        }

        cout << ans << endl;

    }





    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1238778736680874x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
 #include <iostream>

 #include <bitset>

 #include <algorithm>

 

 using namespace std;

 

 bitset<10000> cookie[10];

 

 int main() {

    int r;

     int c;

     while (cin >> r >> c && r > 0) {

         int i, j;

         

         for (i = 0; i < r; i++) {

             for (j = 0; j < c; j++) {

                 bool upwards;

                 cin >> upwards;

                 cookie[i][j] = upwards;

             }

         }

         

         int result = 0;

         int permute = 1 << r;

         for (i = 0; i < permute; i++) {

            for (j = 0; j < r; j++) {

             if (i & 1 << j) {

                 cookie[j].flip();

             }

            }

            

            int possibleResult = 0;

            for (int p = 0; p < c; p++) {

             int upCount = 0;

             for (int q = 0; q < r; q++) {

                 if (cookie[q][p]) {

                     upCount++;

                 }

             }

             possibleResult += max(upCount, r - upCount);

            }

            result = max(result, possibleResult);   

             

            for (j = 0; j < r; j++) {

                if (i & 1 << j) {

                    cookie[j].flip();

                }

            }                                

        }

        cout << result << endl;

     }   

     return 0;

 }

// Faster C++ solution for the same problem (measured speedup: 5.16809432332288x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<bitset>

using namespace std;

bitset<10000> cookie[10];

bool now;

int main()

{

	int r,c;

	while(cin>>r>>c && r>0)

	{

		int i,j;

		for(int i=0;i<r;i++)

		{

			for(int j=0;j<c;j++)

			{

				cin>>now;

				cookie[i][j]=now;

			}

		}

		int ans=0;

		for(int i=0;i<(1<<r);i++)

		{

			for(int j=0;j<r;j++)

			{

				if(i & (1<<j))

				{

					cookie[j].flip();

				}

			}

			

			int possible_ans=0;

			for(int j=0;j<c;j++)

			{

				int up_cookie=0;

				for(int k=0;k<r;k++)

				{

					if(cookie[k][j])

					up_cookie++;

				}

				possible_ans+=max(up_cookie,r-up_cookie); 

			}

			ans=max(ans,possible_ans);

			

			for(int j=0;j<r;j++)

			{

				if(i & (1<<j))

				{

					cookie[j].flip();

				}

			}

			

		}

		printf("%d\n",ans);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.149384189647208x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
//

// Created by Tnecesoc on 2017/4/14.

//



#include <stdio.h>

#include <bitset>



using namespace std;



const int MAX_R = 20;

const int MAX_C = 10000 + 10;



int field[MAX_R][MAX_C];



bitset<MAX_C> toast[MAX_R];



void solve(int fr, int r, int c, int &min) {



    if (fr >= r) {



        int sum = 0;



        for (int i = 0; i < c; ++i) {

            int row_sum = 0;

            for (int j = 0; j < r; ++j) {

                if (toast[j][i]) {

                    row_sum++;

                }

            }



            sum += row_sum < r - row_sum ? row_sum : r - row_sum;

        }



        if (min > sum) {

            min = sum;

        }



        return;

    } else {



        solve(fr + 1, r, c, min);



        toast[fr].flip();



        solve(fr + 1, r, c, min);



    }



}



int main() {

    

    int r, c;

    while (~scanf("%d %d", &r, &c), r | c) {

        for (int i = 0; i < r; ++i) {

            for (int j = 0; j < c; ++j) {

                scanf("%d", &field[i][j]);

                toast[i].set((size_t) j, (bool) field[i][j]);

            }

        }



        int ans = 0x7fffffff;

        solve(0, r, c, ans);

        printf("%d\n", r * c - ans);

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.757197339594723x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXM 10000

#define MAXN 10



int n,m,ans;

bool st[MAXN+3][MAXM+3];



void Dfs(int i) {

	if(i>n) {

		int tot=0;

		for(int j=1;j<=m;j++) {

			int sum=0;

			for(int k=1;k<=n;k++)

				sum+=st[k][j];

			tot+=max(sum,n-sum);

		}

		ans=max(ans,tot);

		return ;

	}

	Dfs(i+1);

	for(int j=1;j<=m;j++)

		st[i][j]=!st[i][j];

	Dfs(i+1);

}

int main() {

	while(scanf("%d %d",&n,&m)&&n&&m) {

		ans=0;

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				scanf("%d",&st[i][j]);

		Dfs(1); printf("%d\n",ans);

	}

	return 0;

}