stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



bitset<10000> maze[10];



int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    int r, c;

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

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

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

                bool tmp;

                cin >> tmp;

                maze[i][j] = tmp;

            }

        int time = 1 << r;

        int ans = 0;

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

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

                if(i & (1 << j))

                    maze[j].flip();

            int result = 0;

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

                int cntpercol = 0;

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

                    if(maze[R][C])

                        ++cntpercol;

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

            }

            ans = max(ans, result);

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

                if(i & (1 << j))

                    maze[j].flip();

        }

        cout << ans << endl;

    }

    return 0;

}

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

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

using namespace std;

#define MAX_R 10

#define MAX_C 10000

int R,C;

int res;

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

int main(){

    while(cin >> R >> C){

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

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

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

                cin >> G[i][j];

        int BIT_SIZE = 1 << R;

        res = 0;

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

            int total = 0;

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

                int k = j;

                int num0 = 0,num1 = 0;

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

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

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

                    k >>= 1;

                }

                total += max(num0,num1);

            }

            res = max(res,total);

        }

        cout << res << endl;

    }

    return 0;

}

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

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

#include <cstdlib>

#include <cstring>

bool table[12][10005];

using namespace std;

int r,c;

int ans;

int ji(){

    int op=0;

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

        int a=0,b=0;

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

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

            else b++;

        }

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

    }

    return op;

}

void br(int now){

    if(now>r){

        int bi=ji();

        ans=ans>bi?ans:bi;

        return ;

    }

    br(now+1);

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

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

        else table[now][i]=true;

    br(now+1);

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

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

        else table[now][i]=true;

}

int main(void){

    while(cin>>r>>c){

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

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

        ans=-1000000;

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

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

                cin>>table[i][j];

            }

        br(1);

        cout<<ans<<endl;

    }

    return 0;

}

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

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

#include<cstring>

#include<iostream>

#include<bitset>



using namespace std;



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

int mapp[MAXR][MAXC];

int r, c;





int main()

{

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

    {

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

        {

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

            {

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

            }

        }

        int ans = 0;

        bitset<32> bs;

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

        int m = bs.to_ulong();

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

        {

            bs = i;

            int cnt = 0;

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

            {

                int cnt1 = 0, cnt0 = 0;

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

                {

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

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

                    else cnt0++;

                }

                cnt+= max(cnt1, cnt0);

            }

            ans = max(ans, cnt);

        }

        cout << ans << endl;

    }





    return 0;

}

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

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

 #include <algorithm>

 

 using namespace std;

 

 bitset<10000> cookie[10];

 

 int main() {

    int r;

     int c;

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

         int i, j;

         

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

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

                 bool upwards;

                 cin >> upwards;

                 cookie[i][j] = upwards;

             }

         }

         

         int result = 0;

         int permute = 1 << r;

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

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

             if (i & 1 << j) {

                 cookie[j].flip();

             }

            }

            

            int possibleResult = 0;

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

             int upCount = 0;

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

                 if (cookie[q][p]) {

                     upCount++;

                 }

             }

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

            }

            result = max(result, possibleResult);   

             

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

                if (i & 1 << j) {

                    cookie[j].flip();

                }

            }                                

        }

        cout << result << endl;

     }   

     return 0;

 }

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

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

using namespace std;

bitset<10000> cookie[10];

bool now;

int main()

{

	int r,c;

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

	{

		int i,j;

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

		{

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

			{

				cin>>now;

				cookie[i][j]=now;

			}

		}

		int ans=0;

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

		{

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

			{

				if(i & (1<<j))

				{

					cookie[j].flip();

				}

			}

			

			int possible_ans=0;

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

			{

				int up_cookie=0;

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

				{

					if(cookie[k][j])

					up_cookie++;

				}

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

			}

			ans=max(ans,possible_ans);

			

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

			{

				if(i & (1<<j))

				{

					cookie[j].flip();

				}

			}

			

		}

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

	}

	return 0;

}

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

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

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

//



#include <stdio.h>

#include <bitset>



using namespace std;



const int MAX_R = 20;

const int MAX_C = 10000 + 10;



int field[MAX_R][MAX_C];



bitset<MAX_C> toast[MAX_R];



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



    if (fr >= r) {



        int sum = 0;



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

            int row_sum = 0;

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

                if (toast[j][i]) {

                    row_sum++;

                }

            }



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

        }



        if (min > sum) {

            min = sum;

        }



        return;

    } else {



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



        toast[fr].flip();



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



    }



}



int main() {

    

    int r, c;

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

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

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

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

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

            }

        }



        int ans = 0x7fffffff;

        solve(0, r, c, ans);

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

    }



    return 0;

}

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

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

}

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

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

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

}

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

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

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;

	}

	

}

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

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

}