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.1272712489738705x):
#include <iostream>

#include <algorithm>

#include <queue>

#include <map>

#include <string>

#include <sstream>

#include <set>

#include <bitset>

using namespace std;



int r, c;

bitset<10000> cookie[10];



int main() {

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

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

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

                bool upward;

                cin >> upward;

                cookie[i][j] = upward;

            }

        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_count = 0;

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

                    if (cookie[k][j]) up_cookie_count++;

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



            }

            ans = max(ans, possible_ans);

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

                if (i & (1 << j)) cookie[j].flip();

        }

        cout << ans << endl;

    }

    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: 10.241006201921621x):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,m;

int a[100][10010];

int maxn=0;

void dfs(int x)

{

	if(x==n+1)

	{

		int t=0;

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

		{

			int s=0;

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

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

			s++;

	    	t+=max(s,n-s);

		}

		maxn=max(maxn,t);

		return ;

	}

	dfs(x+1);

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

	{

		a[x][j]=!a[x][j];

	}

	dfs(x+1);

}

int main()

{

	while(scanf("%d%d",&n,&m)!=EOF&&(n+m))

	{

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

		{

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

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

		}

		dfs(0);

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

	}

	

    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: 1.1506551551505906x):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,m;

int a[100][10010];

int maxn=0;

void dfs(int x)

{

	if(x==n+1)

	{

		int t=0;

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

		{

			int s=0;

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

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

			s++;

	    	t+=max(s,n-s);

		}

		maxn=max(maxn,t);

		return ;

	}

	dfs(x+1);

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

	{

		a[x][j]=!a[x][j];

	}

	dfs(x+1);

}

int main()

{

	while(scanf("%d%d",&n,&m)!=EOF&&(n+m))

	{

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

		{

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

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

		}

		dfs(0);

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

	}

	

    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: 10.26144542916137x):
#include <bits/stdc++.h>

#define d(a) cout << #a << " is " << a << endl

using namespace std;



bool state[10][10000],rflip[10];

int ccol,nr,nc,gmin;

char cc;



int main()

{

    while (scanf("%d%d",&nr,&nc)&&nr+nc) {

        gmin=10000000;

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

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

            scanf(" %c",&cc);

            state[i][c]=cc-'0';

        }

        for(int btmsk=0;btmsk<1<<nr;btmsk++) {

            //d(btmsk);

            for(int i=0;i<nr;i++) rflip[i]=btmsk>>i&1;

            int ans=0;

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

                ccol=0;

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

                    ccol+=state[i][c]^rflip[i];

                ans+=min(ccol,nr-ccol);

            }

            //d(ans);

            gmin=min(gmin,ans);

        }

        printf("%d\n",nr*nc-gmin);

    }

    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: 1.1529516582213821x):
#include <bits/stdc++.h>

#define d(a) cout << #a << " is " << a << endl

using namespace std;



bool state[10][10000],rflip[10];

int ccol,nr,nc,gmin;

char cc;



int main()

{

    while (scanf("%d%d",&nr,&nc)&&nr+nc) {

        gmin=10000000;

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

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

            scanf(" %c",&cc);

            state[i][c]=cc-'0';

        }

        for(int btmsk=0;btmsk<1<<nr;btmsk++) {

            //d(btmsk);

            for(int i=0;i<nr;i++) rflip[i]=btmsk>>i&1;

            int ans=0;

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

                ccol=0;

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

                    ccol+=state[i][c]^rflip[i];

                ans+=min(ccol,nr-ccol);

            }

            //d(ans);

            gmin=min(gmin,ans);

        }

        printf("%d\n",nr*nc-gmin);

    }

    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: 10.091738253631167x):
//Problem:

//Date:

//Skill:



#define CLR(a) memset((a),0,sizeof(a))

#define MAX 2140000000;

#define RE(i,n)  for(i=0;i<n;i++)

#define RE2(i,n) for(i=1;i<=n;i++)

#include<algorithm>

#include<iostream>

#include<time.h>

#include<string.h>



using namespace std;

bool map[11][10010];

int m, n;

int add(int y)

{

	int ans(0);

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

	{

		ans += map[i][y];

	}

	//cout << max(ans, m - ans) << endl;

	return max(ans, m - ans);



}

void change(int num)

{

	int i,j;

	RE2(i, m)//第1到m位

	{

		if(num&(1<<(i-1)))

			RE2(j, n)

		{

			map[i][j] = !map[i][j];

		}

	}

}

int search()

{

	int ans(0);

	int i, j, k;

	for (i = 0; i < (1 << m); i++)//遍历每一种情况

	{

		int maxnum(0);

		change(i);



		RE2(j, n)

		{

			maxnum+= add(j);

		}

		ans = max(ans, maxnum);



		change(i);

	}

	return ans;

}



//#define LOCAL

int main()

{

#ifdef LOCAL



	freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);

	//	freopen("C:\\Users\\VULCAN\\Desktop\\data.out", "w", stdout);

#endif

	//这是一条帅气的分界线，写程序从这里开始吧

	int i, j, k;

	

	while (cin >> m >> n,m)

	{

		RE2(i, m)RE2(j, n)

		{

			cin >> map[i][j];//输入

//			cout << map[i][j];

		}

		int ans=search();

		cout << ans << endl;

	}

















	//这是一条可爱的分界线

#ifdef LOCAL

	printf("用时%.3f秒\n", (double)clock() / CLOCKS_PER_SEC);

#endif

	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: 1.1338837626904497x):
//Problem:

//Date:

//Skill:



#define CLR(a) memset((a),0,sizeof(a))

#define MAX 2140000000;

#define RE(i,n)  for(i=0;i<n;i++)

#define RE2(i,n) for(i=1;i<=n;i++)

#include<algorithm>

#include<iostream>

#include<time.h>

#include<string.h>



using namespace std;

bool map[11][10010];

int m, n;

int add(int y)

{

	int ans(0);

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

	{

		ans += map[i][y];

	}

	//cout << max(ans, m - ans) << endl;

	return max(ans, m - ans);



}

void change(int num)

{

	int i,j;

	RE2(i, m)//第1到m位

	{

		if(num&(1<<(i-1)))

			RE2(j, n)

		{

			map[i][j] = !map[i][j];

		}

	}

}

int search()

{

	int ans(0);

	int i, j, k;

	for (i = 0; i < (1 << m); i++)//遍历每一种情况

	{

		int maxnum(0);

		change(i);



		RE2(j, n)

		{

			maxnum+= add(j);

		}

		ans = max(ans, maxnum);



		change(i);

	}

	return ans;

}



//#define LOCAL

int main()

{

#ifdef LOCAL



	freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);

	//	freopen("C:\\Users\\VULCAN\\Desktop\\data.out", "w", stdout);

#endif

	//这是一条帅气的分界线，写程序从这里开始吧

	int i, j, k;

	

	while (cin >> m >> n,m)

	{

		RE2(i, m)RE2(j, n)

		{

			cin >> map[i][j];//输入

//			cout << map[i][j];

		}

		int ans=search();

		cout << ans << endl;

	}

















	//这是一条可爱的分界线

#ifdef LOCAL

	printf("用时%.3f秒\n", (double)clock() / CLOCKS_PER_SEC);

#endif

	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: 10.099309330693636x):
#include<iostream>

#include<algorithm>

using namespace std;

bool s[15][10005] = { 0 };

int ans = 0, n, m;

void dfs(int x)

{

	if (x == n)

	{

		int sum = 0, temp = 0;

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

		{

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

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

					temp++;

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

			temp = 0;

		}

		ans = max(ans, sum);

		return;

	 }

	dfs(x + 1);

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

		s[x][i] = !s[x][i];

	dfs(x + 1);

}

int main()

{

	while (cin >> n >> m, n, m)

	{

		ans = 0;

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

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

				cin >> s[i][j];

		dfs(0);

		cout << ans << endl;

	}

	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: 1.1347344309431784x):
#include<iostream>

#include<algorithm>

using namespace std;

bool s[15][10005] = { 0 };

int ans = 0, n, m;

void dfs(int x)

{

	if (x == n)

	{

		int sum = 0, temp = 0;

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

		{

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

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

					temp++;

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

			temp = 0;

		}

		ans = max(ans, sum);

		return;

	 }

	dfs(x + 1);

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

		s[x][i] = !s[x][i];

	dfs(x + 1);

}

int main()

{

	while (cin >> n >> m, n, m)

	{

		ans = 0;

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

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

				cin >> s[i][j];

		dfs(0);

		cout << ans << endl;

	}

	return 0;

}
// 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.18172290385013x):
#include <cstdio>

#include <algorithm>

using namespace std;

int M[15][10005];

int r, c, ans;

void Dfs(int now){

    if(now == r){

        int res = 0;

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

            int on = 0;

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

                if(M[j][i] == 1) on++;

            res += max(on, r - on);

        }

        ans = max(ans, res);

        return ;

    }

    Dfs(now + 1);

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

        M[now][i] = 1 - M[now][i];

    Dfs(now + 1);

}

int main(){

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

        if(!r && !c) break;

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

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

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

        ans = 0; Dfs(0);

        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.185907381608858x):
#include <cstdio>

#include <algorithm>

using namespace std;

int M[15][10005];

int r, c, ans;

void Dfs(int now){

    if(now == r){

        int res = 0;

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

            int on = 0;

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

                if(M[j][i] == 1) on++;

            res += max(on, r - on);

        }

        ans = max(ans, res);

        return ;

    }

    Dfs(now + 1);

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

        M[now][i] = 1 - M[now][i];

    Dfs(now + 1);

}

int main(){

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

        if(!r && !c) break;

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

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

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

        ans = 0; Dfs(0);

        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.93590021198208x):
#include <cstdio>

#include <algorithm>

using namespace std;

int M[15][10005];

int r, c, ans;

void Dfs(int now){

    if(now == r){

        int res = 0;

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

            int on = 0;

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

                if(M[j][i] == 1) on++;

            res += max(on, r - on);

        }

        ans = max(ans, res);

        return ;

    }

    Dfs(now + 1);

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

        M[now][i] = 1 - M[now][i];

    Dfs(now + 1);

}

int main(){

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

        if(!r && !c) break;

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

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

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

        ans = 0; Dfs(0);

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

    }



    return 0;

}