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

}

// Faster C++ solution for the same problem (measured speedup: 5.092052472600945x):
/*

 * 题目: 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<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);

    }

}

// Faster C++ solution for the same problem (measured speedup: 5.063160832616701x):
/*

 * 题目: 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 <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;

}


// Faster C++ solution for the same problem (measured speedup: 5.1746886669021555x):
/*

 * 题目: 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>

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

}




// Faster C++ solution for the same problem (measured speedup: 5.069527330128985x):
/*

 * 题目: 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 <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;

}




// Faster C++ solution for the same problem (measured speedup: 5.059429608339796x):
/*

 * 题目: 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:
//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.144511235215749x):
/*

 * 题目: 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<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.140654586237567x):
/*

 * 题目: 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 <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.871381437322951x):
/*

 * 题目: 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:
//============================================================================

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

 * 题目: 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<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.12307920909211x):
/*

 * 题目: 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;

}