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.2247808781854406x):
//

// 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;

}
// 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: 9.963472849304036x):
#include <iostream>

#include <vector>

#include <queue>

#include <string>

#include <cmath>

#include <sstream>

#include <algorithm>



using namespace std;

vector<vector<int> > senbei;

int H, W;





int main() {

	while (1) {

		cin >> H >> W;

		if (H + W == 0) break;

		senbei.resize(H);

		vector<int> b;

		b.resize(H);

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

			senbei[i].resize(W);

			b[i] = 0;

		}

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

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

				cin >> senbei[i][j];

			}

		}

		int H2 = pow(2, H);

		int max = -1;

		

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

			if (i != 0) {

				for (int j = 0; j < b.size(); j++) {

					if (b[j] == 0) {

						b[j] = 1;

						break;

					}

					else {

						b[j] = 0;

					}

				}

			}

			int count = 0;



			for (int k = 0; k < W; k++) {

				int omote = 0, ura = 0;

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

					if (b[j] == senbei[j][k]) omote++;

				}

				count += omote > H-omote ? omote : H-omote;

			}

			if (max < count) max = count;

		}

		cout << max << 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.1194721662314226x):
#include <iostream>

#include <vector>

#include <queue>

#include <string>

#include <cmath>

#include <sstream>

#include <algorithm>



using namespace std;

vector<vector<int> > senbei;

int H, W;





int main() {

	while (1) {

		cin >> H >> W;

		if (H + W == 0) break;

		senbei.resize(H);

		vector<int> b;

		b.resize(H);

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

			senbei[i].resize(W);

			b[i] = 0;

		}

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

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

				cin >> senbei[i][j];

			}

		}

		int H2 = pow(2, H);

		int max = -1;

		

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

			if (i != 0) {

				for (int j = 0; j < b.size(); j++) {

					if (b[j] == 0) {

						b[j] = 1;

						break;

					}

					else {

						b[j] = 0;

					}

				}

			}

			int count = 0;



			for (int k = 0; k < W; k++) {

				int omote = 0, ura = 0;

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

					if (b[j] == senbei[j][k]) omote++;

				}

				count += omote > H-omote ? omote : H-omote;

			}

			if (max < count) max = count;

		}

		cout << max << 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.04526458424425x):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<queue>

#include<map>

#include<string>

#include<sstream>

#include<vector>

#include<cmath>

#include<set>

#include <bitset>

using namespace std;

const int maxn=10015,inf=0x3f3f3f3f;

int r,c,ans;

bitset<maxn> cookie[10];



void dfs(int step){	

	if(step==r){

		int sum=0,csum=0;

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

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

				csum+=cookie[j][i];

			}

			sum=sum+max(csum,r-csum);

			csum=0;

		}

		ans=max(ans,sum);

		return;//attenion return

	}

	cookie[step].flip();

	dfs(step+1);

	cookie[step].flip();

	dfs(step+1);

	

}

int main()

{

	//freopen("read.txt", "r", stdin);

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

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

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

				bool val;

				cin>>val;

				cookie[i][j]=val;

			}

		}

		ans=0;

		dfs(0);

		cout<<ans<<endl;

	}

	//fclose(stdin);

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

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<queue>

#include<map>

#include<string>

#include<sstream>

#include<vector>

#include<cmath>

#include<set>

#include <bitset>

using namespace std;

const int maxn=10015,inf=0x3f3f3f3f;

int r,c,ans;

bitset<maxn> cookie[10];



void dfs(int step){	

	if(step==r){

		int sum=0,csum=0;

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

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

				csum+=cookie[j][i];

			}

			sum=sum+max(csum,r-csum);

			csum=0;

		}

		ans=max(ans,sum);

		return;//attenion return

	}

	cookie[step].flip();

	dfs(step+1);

	cookie[step].flip();

	dfs(step+1);

	

}

int main()

{

	//freopen("read.txt", "r", stdin);

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

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

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

				bool val;

				cin>>val;

				cookie[i][j]=val;

			}

		}

		ans=0;

		dfs(0);

		cout<<ans<<endl;

	}

	//fclose(stdin);

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

#include<algorithm>

using namespace std;

int m, n, ans = 0, temp;

int a[15][10005];

void dfs(int d)

{

	int up;

	if (d == m)

	{

		temp = 0;

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

		{

			up = 0;

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

				if (a[i][j])

					up++;

			temp += max(up, m - up);

		}

		ans = max(ans, temp);

		return;

	}

	dfs(d + 1);

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

		if (a[d][j])

			a[d][j] = 0;

		else

			a[d][j] = 1;

	dfs(d + 1);

}

int main(void)

{

	while (cin >> m >> n)

	{

		if (!m)

			break;

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

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

				cin >> a[i][j];

		dfs(1);

		cout << ans << endl;

	}

	

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

#include<algorithm>

using namespace std;

int m, n, ans = 0, temp;

int a[15][10005];

void dfs(int d)

{

	int up;

	if (d == m)

	{

		temp = 0;

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

		{

			up = 0;

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

				if (a[i][j])

					up++;

			temp += max(up, m - up);

		}

		ans = max(ans, temp);

		return;

	}

	dfs(d + 1);

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

		if (a[d][j])

			a[d][j] = 0;

		else

			a[d][j] = 1;

	dfs(d + 1);

}

int main(void)

{

	while (cin >> m >> n)

	{

		if (!m)

			break;

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

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

				cin >> a[i][j];

		dfs(1);

		cout << ans << endl;

	}

	

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

#include <cstdio>

#include <bitset>

#include <algorithm>

using namespace std;

int R, C, t, ans;

bitset<10005>b[15];



/*首先，翻?行列的次序不影??果，因?行的范??小，可以枚?所有行状?，即把行先翻?完?，

?于??行状?，在?列中??最?解，?行列翻?，即判断0多?是1多,1多?相当于不翻??列，

0多相当于翻??列，因此用bitset容器方便?理。*/

void dfs(int k)

{

    if(k == R)

    {

        int tmp = 0;

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

        {

            int num = 0;

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

                if(b[j][i]) num++;

            tmp += max(num, R-num);

        }

        ans = max(ans, tmp);

        return;

    }

    dfs(k+1);

    b[k].flip();

    dfs(k+1);

    //b[k].flip();

}



int main()

{

    while(~scanf("%d%d",&R,&C),R+C)

    {

        ans = -1;

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

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

            {

                scanf("%d",&t);

                b[i][j] = t;

            }

        dfs(0);

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

#include <cstdio>

#include <bitset>

#include <algorithm>

using namespace std;

int R, C, t, ans;

bitset<10005>b[15];



/*首先，翻?行列的次序不影??果，因?行的范??小，可以枚?所有行状?，即把行先翻?完?，

?于??行状?，在?列中??最?解，?行列翻?，即判断0多?是1多,1多?相当于不翻??列，

0多相当于翻??列，因此用bitset容器方便?理。*/

void dfs(int k)

{

    if(k == R)

    {

        int tmp = 0;

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

        {

            int num = 0;

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

                if(b[j][i]) num++;

            tmp += max(num, R-num);

        }

        ans = max(ans, tmp);

        return;

    }

    dfs(k+1);

    b[k].flip();

    dfs(k+1);

    //b[k].flip();

}



int main()

{

    while(~scanf("%d%d",&R,&C),R+C)

    {

        ans = -1;

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

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

            {

                scanf("%d",&t);

                b[i][j] = t;

            }

        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: 10.253883403073877x):
#include<algorithm>

#include<iostream>

#include<cstring>

#include<climits>

#include<cstdio>

using namespace std;

int f[15][10005];

int r,c,ans=0;

void dfs(int row)

{

    if(row==r+1)

    {

        int cont1=0;  

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

        {  

            int cont2=0;

            for(int j=1;j<=r;j++)if(f[j][i]==1)cont2++;  

            cont1+=max(cont2,r-cont2);  

        }  

        ans=max(ans,cont1);  

        return ;

    }

    dfs(row+1);

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

    if(f[row][i])f[row][i]=0;

    else f[row][i]=1;

    dfs(row+1);

}

int main()

{   

    while(1)

    {

        ans=0;

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

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

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

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

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

        dfs(1);

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

    }

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

#include<iostream>

#include<cstring>

#include<climits>

#include<cstdio>

using namespace std;

int f[15][10005];

int r,c,ans=0;

void dfs(int row)

{

    if(row==r+1)

    {

        int cont1=0;  

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

        {  

            int cont2=0;

            for(int j=1;j<=r;j++)if(f[j][i]==1)cont2++;  

            cont1+=max(cont2,r-cont2);  

        }  

        ans=max(ans,cont1);  

        return ;

    }

    dfs(row+1);

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

    if(f[row][i])f[row][i]=0;

    else f[row][i]=1;

    dfs(row+1);

}

int main()

{   

    while(1)

    {

        ans=0;

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

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

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

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

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

        dfs(1);

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

    }

}
// 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.03288587402929x):
#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;

}