stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//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;

}












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

const int MAXR = 10;

const int MAXC = 10000;

int R, C;

int a[MAXR][MAXC];

#include <algorithm>

void reverse(int x) {

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

        a[x][i] = !a[x][i];

}

int dfs(int cur) {

    int ans = 0;

    if (cur == R) {

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

            int cnt = 0;

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

                cnt += a[i][j];

            ans += std::max(cnt, R - cnt);

        }

    }

    else {

        ans = dfs(cur + 1);

        reverse(cur);

        ans = std::max(ans, dfs(cur + 1));

        //reverse(cur);

    }

    return ans;

}

int solve() {

    return dfs(0);

}

int main() {

    while (scanf("%d%d", &R, &C), R) {

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

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

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

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

    }

    return 0;

}
// Slower C++ solution:
#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;

}


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

const int MAXR = 10;

const int MAXC = 10000;

int R, C;

int a[MAXR][MAXC];

#include <algorithm>

void reverse(int x) {

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

        a[x][i] = !a[x][i];

}

int dfs(int cur) {

    int ans = 0;

    if (cur == R) {

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

            int cnt = 0;

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

                cnt += a[i][j];

            ans += std::max(cnt, R - cnt);

        }

    }

    else {

        ans = dfs(cur + 1);

        reverse(cur);

        ans = std::max(ans, dfs(cur + 1));

        //reverse(cur);

    }

    return ans;

}

int solve() {

    return dfs(0);

}

int main() {

    while (scanf("%d%d", &R, &C), R) {

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

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

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

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

    }

    return 0;

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

const int MAXR = 10;

const int MAXC = 10000;

int R, C;

int a[MAXR][MAXC];

#include <algorithm>

void reverse(int x) {

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

        a[x][i] = !a[x][i];

}

int dfs(int cur) {

    int ans = 0;

    if (cur == R) {

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

            int cnt = 0;

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

                cnt += a[i][j];

            ans += std::max(cnt, R - cnt);

        }

    }

    else {

        ans = dfs(cur + 1);

        reverse(cur);

        ans = std::max(ans, dfs(cur + 1));

        //reverse(cur);

    }

    return ans;

}

int solve() {

    return dfs(0);

}

int main() {

    while (scanf("%d%d", &R, &C), R) {

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

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

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

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

    }

    return 0;

}
// Slower C++ solution:
//============================================================================

// Name        : Osenbei

// Author      : seaupnice

// Version     :

// Copyright   : Your copyright notice

// Description : Hello World in C++, Ansi-style

//============================================================================



#include<bits/stdc++.h>

using namespace std;



const int MAX_R=10;

const int MAX_C=10000;

bitset<MAX_C> maze[MAX_R];

int R,C;

int ans;

/* dfs()全排列*/

void dfs(int k){

	if(k==C){

		int result=0;

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

			int upnum=0;

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

				if(maze[j][i]){

					upnum++;

				}

			}

			result += max(upnum,C-upnum);

		}

		ans = max(ans, result);

		return;

	}

	dfs(k+1);

	maze[k].flip();

	dfs(k+1);

}



int main(){

	while((cin >> C >> R) && C && R){

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

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

				int a;

				scanf("%d",&a);

				maze[i][j] = (a==1?true:false);

			}

		}

		ans=0;

		dfs(1);

		cout << ans << endl;

	}

	return 0;

}




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

const int MAXR = 10;

const int MAXC = 10000;

int R, C;

int a[MAXR][MAXC];

#include <algorithm>

void reverse(int x) {

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

        a[x][i] = !a[x][i];

}

int dfs(int cur) {

    int ans = 0;

    if (cur == R) {

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

            int cnt = 0;

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

                cnt += a[i][j];

            ans += std::max(cnt, R - cnt);

        }

    }

    else {

        ans = dfs(cur + 1);

        reverse(cur);

        ans = std::max(ans, dfs(cur + 1));

        //reverse(cur);

    }

    return ans;

}

int solve() {

    return dfs(0);

}

int main() {

    while (scanf("%d%d", &R, &C), R) {

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

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

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

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

    }

    return 0;

}
// Slower C++ solution:
#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);

    }

}




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

const int MAXR = 10;

const int MAXC = 10000;

int R, C;

int a[MAXR][MAXC];

#include <algorithm>

void reverse(int x) {

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

        a[x][i] = !a[x][i];

}

int dfs(int cur) {

    int ans = 0;

    if (cur == R) {

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

            int cnt = 0;

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

                cnt += a[i][j];

            ans += std::max(cnt, R - cnt);

        }

    }

    else {

        ans = dfs(cur + 1);

        reverse(cur);

        ans = std::max(ans, dfs(cur + 1));

        //reverse(cur);

    }

    return ans;

}

int solve() {

    return dfs(0);

}

int main() {

    while (scanf("%d%d", &R, &C), R) {

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

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

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

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

    }

    return 0;

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

#include<stdio.h>

#include<math.h>

#include<algorithm>

using namespace std;

int n,m;  int map[13][100003];  int book[13]; int ans; int newmap[13][100003]; int max0,max1; int preans;

void answer();

void dfs(int x)

{

	if(x==n+1) answer();

	else 

	{

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

		{

			book[x]=i;

			dfs(x+1);

		}

	}

}



void answer()

{

	 preans=0;

    

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

	{

		if(book[i])

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

		{

			newmap[i][j]=(map[i][j]+1)%2;

		}

		else 

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

		{

			newmap[i][j]=map[i][j];

		}

	}



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

	{

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

		{

			if(newmap[j][i]==0)  max0++;

			else max1++;

		}

		 preans+=max(max0,max1);

		 max1=0; max0=0;

	}

	ans=max(ans,preans);

}





int main()

{

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

   	{

   		   ans=0; preans=0;

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

   		  {

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

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

		  }

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

       {

       	  book[1]=i;

       	  dfs(2);

	   }

	   cout<<ans<<endl;

	}

	return 0;

}


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

const int MAXR = 10;

const int MAXC = 10000;

int R, C;

int a[MAXR][MAXC];

#include <algorithm>

void reverse(int x) {

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

        a[x][i] = !a[x][i];

}

int dfs(int cur) {

    int ans = 0;

    if (cur == R) {

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

            int cnt = 0;

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

                cnt += a[i][j];

            ans += std::max(cnt, R - cnt);

        }

    }

    else {

        ans = dfs(cur + 1);

        reverse(cur);

        ans = std::max(ans, dfs(cur + 1));

        //reverse(cur);

    }

    return ans;

}

int solve() {

    return dfs(0);

}

int main() {

    while (scanf("%d%d", &R, &C), R) {

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

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

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

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

    }

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

#include <cstdio>

#include <cmath>

#include <iomanip>

#include <vector>

#include <map>

#include <cstring>

#include <algorithm>

using namespace std;



struct Coordinate{

    int row;

    int col;

};

Coordinate mov_dir[4] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};

bool mat[11][10001], one[11];

int R, C, ans;



void dfs(int row, bool flag)

{

    if (row == 10) {

        return;

    }

    if (flag) {

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

            mat[row][j] = !mat[row][j];

        }

    }

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

        int cnt_o = 0, cnt_z = 0;

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

            if (mat[j][i] == 1) {

                cnt_o++;

            }

            else {

                cnt_z++;

            }

        } 

        if (cnt_z > cnt_o) {

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

                mat[j][i] = !mat[j][i];

            }

        }

    }

        int cnt = 0;

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

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

                if (mat[i][j]) {

                    cnt++;

                }

            }

        }

    if (ans < cnt) {

        ans = cnt;

    }    

    dfs(row + 1, true);

    dfs(row + 1, false);



}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    

    while (cin >> R >> C && !(R == 0 && C == 0)) {

        ans = -1;

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

            int cnt_o = 0, cnt_z = 0;

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

                cin >> mat[i][j];

            }    

        }

        dfs(0, true);

        dfs(0, false);



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

 * 题目: Aizu - 0525 

 * 题意: 

 * 类型: 

 * 算法：暴力搜索

 * Date: 2020-07-07 09:37:58

 * LastEditors: loeije

 * LastEditTime: 2020-07-08 07:01:33

*/



#include <cstdio>

#include <cmath>

#include <algorithm>

using namespace std;



const int maxn = 1024 + 10;

const int row = 10 + 5, col = 10000 + 5;

int grid[row][col];

int r, c, ans = 0;



void process(int idx) {

    if(idx == r) {

        int sum = 0;

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

            int tempsum = 0;

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

                if(grid[j][i] == 1) {

                    tempsum++;

                }

            }



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

        }

        ans = max(ans, sum);

        return ;

    }



    process(idx + 1);

    for(int i = 0; i < c; ++i) grid[idx][i] = !grid[idx][i];

    process(idx + 1);

}



int main() {

    while(scanf("%d%d", &r, &c) && (r + c != 0)) {

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

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

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

            }

        }



        // process

        ans = 0;

        process(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.184026230100454x):
/*

 * 题目: Aizu - 0525 

 * 题意: 

 * 类型: 

 * 算法：暴力搜索

 * Date: 2020-07-07 09:37:58

 * LastEditors: loeije

 * LastEditTime: 2020-07-08 07:01:33

*/



#include <cstdio>

#include <cmath>

#include <algorithm>

using namespace std;



const int maxn = 1024 + 10;

const int row = 10 + 5, col = 10000 + 5;

int grid[row][col];

int r, c, ans = 0;



void process(int idx) {

    if(idx == r) {

        int sum = 0;

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

            int tempsum = 0;

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

                if(grid[j][i] == 1) {

                    tempsum++;

                }

            }



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

        }

        ans = max(ans, sum);

        return ;

    }



    process(idx + 1);

    for(int i = 0; i < c; ++i) grid[idx][i] = !grid[idx][i];

    process(idx + 1);

}



int main() {

    while(scanf("%d%d", &r, &c) && (r + c != 0)) {

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

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

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

            }

        }



        // process

        ans = 0;

        process(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.917060828662095x):
/*

 * 题目: Aizu - 0525 

 * 题意: 

 * 类型: 

 * 算法：暴力搜索

 * Date: 2020-07-07 09:37:58

 * LastEditors: loeije

 * LastEditTime: 2020-07-08 07:01:33

*/



#include <cstdio>

#include <cmath>

#include <algorithm>

using namespace std;



const int maxn = 1024 + 10;

const int row = 10 + 5, col = 10000 + 5;

int grid[row][col];

int r, c, ans = 0;



void process(int idx) {

    if(idx == r) {

        int sum = 0;

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

            int tempsum = 0;

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

                if(grid[j][i] == 1) {

                    tempsum++;

                }

            }



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

        }

        ans = max(ans, sum);

        return ;

    }



    process(idx + 1);

    for(int i = 0; i < c; ++i) grid[idx][i] = !grid[idx][i];

    process(idx + 1);

}



int main() {

    while(scanf("%d%d", &r, &c) && (r + c != 0)) {

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

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

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

            }

        }



        // process

        ans = 0;

        process(0);

        

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

 * 题目: Aizu - 0525 

 * 题意: 

 * 类型: 

 * 算法：暴力搜索

 * Date: 2020-07-07 09:37:58

 * LastEditors: loeije

 * LastEditTime: 2020-07-08 07:01:33

*/



#include <cstdio>

#include <cmath>

#include <algorithm>

using namespace std;



const int maxn = 1024 + 10;

const int row = 10 + 5, col = 10000 + 5;

int grid[row][col];

int r, c, ans = 0;



void process(int idx) {

    if(idx == r) {

        int sum = 0;

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

            int tempsum = 0;

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

                if(grid[j][i] == 1) {

                    tempsum++;

                }

            }



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

        }

        ans = max(ans, sum);

        return ;

    }



    process(idx + 1);

    for(int i = 0; i < c; ++i) grid[idx][i] = !grid[idx][i];

    process(idx + 1);

}



int main() {

    while(scanf("%d%d", &r, &c) && (r + c != 0)) {

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

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

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

            }

        }



        // process

        ans = 0;

        process(0);

        

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

    }

    return 0;

}