Problem:
おせんべい
問題
IOI製菓では，創業以来の伝統の製法で煎餅（せんべい）を焼いている．この伝統の製法は，炭火で一定時間表側を焼き，表側が焼けると裏返して，炭火で一定時間裏側を焼くというものである．この伝統を守りつつ，煎餅を機械で焼いている．この機械は縦 R (1 ≤ R ≤ 10) 行, 横 C (1 ≤ C ≤ 10000) 列の長方形状に煎餅を並べて焼く．通常は自動運転で，表側が焼けたら一斉に煎餅を裏返し裏側を焼く．
ある日，煎餅を焼いていると，煎餅を裏返す直前に地震が起こり何枚かの煎餅が裏返ってしまった．幸いなことに炭火の状態は適切なままであったが，これ以上表側を焼くと創業以来の伝統で定められている焼き時間を超えてしまい，煎餅の表側が焼けすぎて商品として出荷できなくなる．そこで，急いで機械をマニュアル操作に変更し，まだ裏返っていない煎餅だけを裏返そうとした．この機械は，横の行を何行か同時に裏返したり縦の列を何列か同時に裏返したりすることはできるが，残念なことに，煎餅を１枚ごと裏返すことはできない．
裏返すのに時間がかかると，地震で裏返らなかった煎餅の表側が焼けすぎて商品として出荷できなくなるので，横の何行かを同時に１回裏返し，引き続き，縦の何列かを同時に１回裏返して，表側を焼きすぎずに両面を焼くことのできる煎餅，つまり，「出荷できる煎餅」の枚数をなるべく多くすることにした．横の行を１行も裏返さない，あるいは，縦の列を１列も裏返さない場合も考えることにする．出荷できる煎餅の枚数の最大値を出力するプログラムを書きなさい．
地震の直後に，煎餅が次の図のような状態になったとする．黒い丸が表側が焼ける状態を，白い丸が裏側が焼ける状態を表している．
1行目を裏返すと次の図のような状態になる．
さらに， 1列目と5列目を裏返すと次の図のような状態になる．この状態では，出荷できる煎餅は9枚である．
ヒント
R の上限 10 は C の上限 10000 に比べて小さいことに注意せよ．
入力
入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．
入力の1行目には2つの整数 R, C (1 ≤ R ≤ 10, 1 ≤ C ≤ 10 000) が空白を区切りとして書かれている．続く R 行は地震直後の煎餅の状態を表す． (i+1) 行目 (1 ≤ i ≤ R) には， C 個の整数 a
i,1
, a
i,2
, ……, a
i,C
が空白を区切りとして書かれており， a
i,j
は i 行 j 列 の煎餅の状態を表している. a
i,j
が 1 なら表側が焼けることを， 0 なら裏側が焼けることを表す．
C, R がともに 0 のとき入力の終了を示す.　データセットの数は 5 を超えない．
出力
データセットごとに，出荷できる煎餅の最大枚数を1行に出力する．
入出力例
入力例
2 5
0 1 0 1 0
1 0 0 0 1
3 6
1 0 0 0 1 0
1 1 1 0 1 0
1 0 1 1 0 1  
0 0
出力例
9
15
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int ans;
int ones[10001]={0};//全局变量一定要及时清理！！！，不然下次循环又累加了
int m,n;
int a[11][10001];
void solve(){
    memset(ones,0,sizeof(ones));//不只是赋值，更是清空
    ans=0;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            ones[j]+=a[i][j];
        }
    }
    int _ones[10001];//每一列的总和
    for(int no=(1<<m)-1;no>=0;no--){//十行都有两种情况的枚举，共2的10次方，1左移64位减去一就是了
        int nos=no;
        for(int i=0;i<n;i++){
            _ones[i]=ones[i];
        }
        for(int i=0;i<m;i++){
            if(nos&1){//1就是翻转，判断此时最后一位是不是1，是的话就把ones的值更新
                for(int j=0;j<n;j++){
                    _ones[j]+=a[i][j]?-1:1;
                }
            }
            nos>>=1;//右移一位nos=nos>>1；判断下一位要不要转
        }
        int tem=0;
        for(int j=0;j<n;j++){
            tem+=max(m-_ones[j],_ones[j]);//每一行都处理好了，这里看每一列翻不翻转哪个大
        }
        ans=max(ans,tem);
    }
}
int main(){
    while(cin>>m>>n&&m>0&&n>0){
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                cin>>a[i][j];
            }
        }
        solve();
        cout<<ans<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3640
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include<utility>
#include<set>
#include<deque>
#include <unordered_map>
#include<string>
#include<map>
#include<cmath>

using namespace std;

int binary(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}

const long long INF = 1LL << 60;
int main() {
	int H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 and W == 0)break;
		vector<vector<int>>M(H, vector<int>(W, 0));

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> M[i][j];
			}
		}
		int A = 1;
		for (int i = 0; i < H; i++) {
			A *= 2;
		}
		A -= 1;
		int ans = 0;
		for (int i = 0; i <= A; i++) {

			string S = to_string(binary(i));

			for (int j = 0; j < S.size(); j++) {
				if (S[j] == '1') {
					for (int k = 0; k < W; k++) {
						if (M[j][k] == 0) {
							M[j][k] = 1;
						}
						else {
							M[j][k] = 0;
						}
					}
				}
			}




			int ka = 0;
			for (int j = 0; j < W; j++) {
				int zc = 0, oc = 0;
				for (int k = 0; k < H; k++) {
					if (M[k][j] == 0) {
						zc += 1;
					}
					else {
						oc += 1;
					}
				}
				ka += max(zc, oc);
			}
			ans = max(ans, ka);
			for (int j = 0; j < S.size(); j++) {
				if (S[j] == '1') {
					for (int k = 0; k < W; k++) {
						if (M[j][k] == 0) {
							M[j][k] = 1;
						}
						else {
							M[j][k] = 0;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 720
memory_kb: 4116
final_rank: 17

code_snippet: #include <iostream>
#include <bitset>
#include <cstdio>

using namespace std;

#define MAX_R 10
#define MAX_C 10000

int w,h;
bitset<MAX_C> mat[MAX_R];
int maxcnt;

void DFS2(int cur)
{
	if(cur==w)
	{
		int cnt=0;
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			if(mat[i][j]) cnt++;

		maxcnt=max(cnt,maxcnt);
		return;
	}

	int cnt0=0,cnt1=0;

	for(int i=0;i<h;i++)
		if(mat[i][cur]) cnt1++;
		else cnt0++;

	if(cnt0>cnt1)
		for(int i=0;i<h;i++) mat[i][cur].flip();

	DFS2(cur+1);
}

void DFS1(int cur)
{
	if(cur==h)
	{
		DFS2(0);
		return;
	}

	mat[cur].flip();
	DFS1(cur+1);
	mat[cur].flip();
	DFS1(cur+1);
}

int main()
{
	scanf("%d%d",&h,&w);

	while(w!=0 || h!=0)
	{
		for(int i=0;i<h;i++)
		{
			mat[i].reset();
			for(int j=0;j<w;j++)
			{
				int val;
				scanf("%d",&val);
				if(val) mat[i][j]=true;
				else mat[i][j]=false;
			}
		}

		maxcnt=0;

		DFS1(0);
		printf("%d\n",maxcnt);

		scanf("%d%d",&h,&w);
	}

	return 0;
}
accuracy: 1
time_ms: 650
memory_kb: 3504
final_rank: 16

code_snippet: #include <iostream>
#include <algorithm>

#define MAXN 10000

using namespace std;

int H, W;
int region[15][MAXN];
int ans;

void dfs(int col) {
    if (col == H) {
        int sum = 0;

        for (int i = 0; i < W; i++) {
            int volsum = 0;
            for (int j = 0; j < H; j++) {
                volsum += region[j][i];
            }

            sum += max(volsum, H - volsum);
        }

        ans = max(ans, sum);
        return;
    }

    dfs(col + 1);

    for (int i = 0; i < W; i++) {
        region[col][i] = !region[col][i];
    }

    dfs(col + 1);

    for (int i = 0; i < W; i++) {
        region[col][i] = !region[col][i];
    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> H >> W, H + W) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> region[i][j];
            }
        }

        ans = 0;
        dfs(0);
        cout << ans << '\n';
    }

    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3852
final_rank: 6

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>

int main() {
  int r, c;
  while (scanf("%d %d", &r, &c) == 2 && r != 0) {
    std::vector<std::vector<int>> g(r, std::vector<int>(c, 0));

    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        scanf("%d", &g[i][j]);
      }
    }

    int ans = 0;

    int b = 0;
    int upper = std::pow(2, r);
    while (b < upper) {
      auto t = g;
      for (int i = 0; i < r; i++) {
        if (b & (1 << i)) {
          for (int j = 0; j < c; j++) {
            t[i][j] = t[i][j] == 1 ? 0 : 1;
          }
        }
      }
      int total = 0;
      for (int j = 0; j < c; j++) {
        int ct = 0;
        for (int i = 0; i < r; i++) {
          if (t[i][j] == 1) {
            ct++;
          }
        }
        total += std::max(ct, r - ct);
      }

      ans = std::max(ans, total);
      b++;
    }

    printf("%d\n", ans);
  }
  return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 3712
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main(){
    while(1){
    int r,c;
    cin >> r >> c;
    if(r==0 && c==0) break;
    vector<vector<int>> grid(r,vector<int>(c));
    rep(i,r){
        rep(j,c){
            cin >> grid[i][j];
        }
    }
    int ans=0;
    for(int bit=0;bit<(1<<r);bit++){
        vector<vector<int>> grid2=grid;
        rep(i,r){
            if(bit&(1<<i)){
                rep(j,c){
                    grid2[i][j]=1-grid2[i][j];
                }
            }
        }
        int res=0;
        rep(j,c){
            int zero=0;
            rep(i,r){
                if(grid2[i][j]==0){
                    zero++;
                }
            }
            res += max(zero,r-zero);
        }
        ans=max(ans,res);
    }
    cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 3808
final_rank: 12

code_snippet: #include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
using namespace std;
using ll = long long;
int grid[11][10001];
int senbeis[10001];
ll H, W;
ll maximum = -1;

void turn(int n){
  if(n == H){
    ll sum = 0;
    for(ll j = 0; j < W; j++){
      sum += max((ll)senbeis[j], H-senbeis[j]);
    }
    maximum = max(maximum, sum);
  }
  else{
    for(int j = 0; j < W; j++){
      if(grid[n][j] == 1){
        grid[n][j] = 0;
        senbeis[j]++;
      }
      else{
        grid[n][j] = 1;
        senbeis[j]--;
      }
    }
    turn(n+1);

    for(int j = 0; j < W; j++){
      if(grid[n][j] == 1){
        grid[n][j] = 0;
        senbeis[j]++;
      }
      else{
        grid[n][j] = 1;
        senbeis[j]--;
      }
    }

    turn(n+1);
  }
}

int main(){
  while(true){
    maximum = -1;
    cin >> H >> W;
    if(H == 0 || W == 0) return 0;
    for(ll j = 0; j < W; j++) senbeis[j] = 0;

    for(ll i = 0; i < H; i++){
      for(ll j = 0; j < W; j++){
         cin >> grid[i][j];
         if(grid[i][j] == 0) senbeis[j]++;
      }
    }
    turn(0);
    cout << maximum << endl;
  }
}
accuracy: 1
time_ms: 120
memory_kb: 3748
final_rank: 8

code_snippet: // https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;

template<typename T>
bool chmax(T& a, const T& b) {
    bool res = a < b;
    a = max(a, b);
    return res;
}
template<typename T>
bool chmin(T& a, const T& b){
    bool res = a > b;
    a = min(a, b);
    return res;
}

typedef vector<long long> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll>> vll;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;

const int inf = 1000000009;
const ll linf = 4000000000000000009;


// https://trap.jp/post/1224/
template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

void print(){
    cout << '\n';
}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){
    cout << a;
    (cout << ... << (cout << ' ', b));
    cout << '\n';
}

#define rep1(a)          for(int i = 0; i < a; i++)
#define rep2(i, a)       for(int i = 0; i < a; i++)
#define rep3(i, a, b)    for(int i = a; i < b; i++)
#define rep4(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)


#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
//---------------------------------

#define MAX_C 10009
int a[MAX_C];
int ans, x;


void solve(int r, int c){
    ans = 0;
    memset(a, 0, c*sizeof(int));
    rep(j, r) rep(i, c){
        cin >> x;
        a[i] += x*(1<<j);
    }
    for(int mask = 0; mask < (1<<r); mask++){
        int cur = 0;
        rep(i, c){
            int aft = mask ^ a[i];
            int pop = __builtin_popcount(aft);
            cur += max(pop, r-pop);
        }
        chmax(ans, cur);
    }
    print(ans);
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int r,c;
    cin >> r >> c;
    while(r > 0){
        solve(r, c);
        cin >> r >> c;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 1

code_snippet: #include<bits/stdc++.h>

using namespace std;


int main(){

    int H, W;

    while(cin >> H >> W && H != 0 && W != 0){

        vector<vector<int> > vec(H, vector<int>(W));

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

                cin >> vec[i][j];

            }
        }

        int result = 0;

        //实现翻转哪一行的外部loop，如果i与bit的论理积为1，则翻转，否则跳过那行
        for(int bit = 0 ; bit < (1<<H) ; bit++){

            vector<vector<int> > vec_copy(vec);

            for(int i = 0 ; i < H ; i ++){
                if(!(bit & (1 << i))) continue;

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

                    vec_copy[i][j] = 1 - vec_copy[i][j];

                }
            }

            int tmp = 0;

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

                int num = 0;

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

                    if(vec_copy[i][j] == 0) num ++;

                }
                tmp += max(num , H-num);

            }

            result = max(result,tmp);


        }

        cout << result << endl;

    }

    return 0;



}
accuracy: 1
time_ms: 210
memory_kb: 3752
final_rank: 11

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
#include <unordered_set>
#include <functional>
using namespace std;
//using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
//void chmin(ll & a, ll b) { a = min(a, b); }
//using mint = modint998244353;

int main() {
	while (true) {
		int r, c;
		int ans = 0;
		cin >> r >> c;
		if (r == 0 && c == 0) {
			break;
		}
		vector o(r, vector<int>(c));
		rep(i, r)rep(j, c) cin >> o[i][j];//1の数の最小化
		
		for (int i = 0; i < (1 << r); i++) {
			vector oc = o;
			for (int j = 0; j < r; j++) {
				if (i & (1 << j)) {
					rep(k, c) {
						oc[j][k] ^= 1;
					}
				}
			}

			vector<int> s(c);
			rep(j, c) {
				int num1 = 0;
				rep(k, r) {
					if (oc[k][j] == 1) {
						num1++;
					}
				}
				s[j] = num1;
			}

			int temp = 0;
			rep(j, c) {
				if (s[j] * 2 > r) {
					temp += s[j];
				}
				else {
					temp += r - s[j];
				}
			}
			ans = max(ans, temp);
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 240
memory_kb: 3972
final_rank: 14

code_snippet: #include "iostream"
#include "vector"

using namespace std;
int c,r;
int g_o[11][10001];
int g_i[11][10001];


int main(){
    while((cin >> r >> c) && (r+c) != 0){
        for(int i = 0 ; i < r; i++){
            for(int j = 0; j < c; j++){
                cin >> g_o[i][j];
                g_i[i][j] = g_o[i][j] ^ 1;
            }
        }
        int ans = 0;

        for(int index = 0; index < (1 << r); index++){
            int result = 0;
            vector<int> cnt_o(c,0);
            for(int i = 0; i < r; i++){
                for(int j = 0; j < c; j++){
                    if((index>>i) & 1) cnt_o[j] += g_i[i][j];
                    else cnt_o[j] += g_o[i][j];
                }
            }
            for(int j = 0; j < c; j++){
                result += max(cnt_o[j], r-cnt_o[j]);
            }
            ans = max(ans, result);
        }
        cout << ans << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3932
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;

int ans;
int n, m;
bool maze[15][10005];
void solve(int step) {
	if (step > n) {
		int sum = 0;
		for (int j = 1; j <= m; ++j) {
			int cnt = 0;
			for (int i = 1; i <= n; ++i) {
				cnt += maze[i][j];
			}
			cnt = max(cnt, n - cnt);
			sum += cnt;
		}
		ans = max(ans, sum);
		return;
	}
	solve(step + 1);
	for (int i = 1; i <= m; ++i) maze[step][i] = !maze[step][i];
	solve(step+1);
	return;
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	while (n && m) {
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; ++j) cin >> maze[i][j];
		ans = 0;
		solve(1);
		cout << ans << '\n';
		cin >> n >> m;
	}
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3568
final_rank: 3

code_snippet: /* c++11 header*/
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <list>

using namespace std;

#define MAGICNUMBER 0x9e3779b9
#define fsio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int INF = 0x3f3f3f3f;
const double EPS = 1e-6;

int r, c, pan;
vector<vector<int>> g;

void changes(int wr) {
    // 对当前第 wr 行进行反转，0 变 1 ，1 变 0
    for (int i = 0; i < c; i++) {
        if (g[wr][i]) {
            g[wr][i] = 0;
            g[r][i]--;      // 对于原先的列 少了一个 1
        } else {
            g[wr][i] = 1;
            g[r][i]++;    // 对于原先的列 多了一个 1
        }
    }
}

void flip(int wr) {
    if (wr == r) {
        int sum = 0;
        for (int i = 0; i < c; i++) {       // 对于每一列 有多少个 1，有多少个 0，实际上选择最多的那一个，我们对这列进行反转
            int one = g[r][i], zero = r - one;
            sum += max(one, zero);
        }
        pan = max(pan, sum);
        return;
    }

    changes(wr);
    flip(wr + 1);
    changes(wr);

    // 不对第 wr 行进行反转，没有任何事情发生
    flip(wr + 1);
}

int main() {
    fsio;
    
    while (cin >> r >> c) {
        if (r == 0 && c == 0) break;

        g.assign(r + 1, vector<int>(c, 0));

        // 目标 0 的数量多
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                cin >> g[i][j];
                g[r][j] += g[i][j];
            }
        }

        pan = 0;
        flip(0);
        cout << pan << "\n";
    }
    
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3396
final_rank: 7

code_snippet: #include<iostream>
#include<bitset>
#define Max_R 10
#define Max_C 10000
using namespace std;

bitset<Max_C> Box[Max_R];
int R,C;

int main()
{
	while(scanf("%d%d",&R,&C),R||C)
	{
		int ans=0;
		bool x;
		for(int i=0;i<R;++i)
		 for(int j=0;j<C;++j)
		  {
		  	cin>>x;
		  	Box[i][j]=x;
		  }
         	 
		 for(int i=0;i<1<<R;++i)
		 {       
		        int sum=0;
		 		 
		 		 for(int j=0;j<R;++j)
		 		 {
				    if(i&(1<<j))
		 	        Box[j].flip();
		 	     }
		        
		        for(int j=0;j<C;++j)
		        {   
		           int temp=0;
		        	for(int k=0;k<R;++k)
		        	{
		        		if(Box[k][j])
		        		 temp++;
					}
					sum+=max(temp,R-temp);
				}
				ans=max(ans,sum);
				
				 for(int j=0;j<R;++j)
		 		 {
				    if(i&(1<<j))
		 	        Box[j].flip();
		 	     }
		        
     	  }
     	cout<<ans<<endl;
    }
	
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3368
final_rank: 5

code_snippet: #include<iostream>
using namespace std;
short b[10][10000];
int R,C;
int sum =0;

void dfs(int t)
{
    if(t==R)
    {
        int ans=0;
        for(int j=0;j<C;j++)
        {
            int tmp=0;
            for(int i=0;i<R;i++)
            {
                tmp+=b[i][j];
            }
            ans+= max(tmp,R-tmp);
        }
        sum = max(sum,ans);
        return;
    }
    dfs(t+1);
    for(int j=0;j<C;j++)
    {
        b[t][j]=1-b[t][j];
    }
    dfs(t+1);
    return;
}

using namespace std;
int main()
{
    while(cin >> R >> C)
    {
        if((R==0)||(C==0)) break;
        if(R<=C)
        {
            //short b[R][C];
            for(int i=0;i<R;i++)
            {
                for(int j=0;j<C;j++)
                {
                    cin >> b[i][j];
                }
            }
        }
        else
        {
            //short b[C][R];
            for(int j=0;j<R;j++)
            {
                for(int i=0;i<C;i++)
                {
                    cin >> b[i][j];
                }
            }
            int tmp;
            tmp = C;
            C = R;
            R = tmp;
        }
        sum = 0;
        dfs(0);
        cout << sum << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3224
final_rank: 2

code_snippet: #include <iostream>
#include <cmath>
using namespace std;

const int MAX_R = 10, MAX_C = 10000;

int R, C;
int board[MAX_C][MAX_R];

int main() {
    while (true) {
        cin >> R >> C;
        if (R == 0 && C == 0)
            return 0;
        int ans = 0;
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                cin >> board[j][i];
            }
        }
        for (int i = 0; i < (1 << R); i++) {
            for (int j = 0; j < R; j++) {
                if ((i >> j) & 1) {
                    for (int k = 0; k < C; k++) {
                        if (board[k][j] == 0)
                            board[k][j] = 1;
                        else
                            board[k][j] = 0;
                    }
                }
            }
            int tmp = 0;
            for (int j = 0; j < C; j++) {
                int head = 0;
                for (int k = 0; k < R; k++) {
                    if (board[j][k] == 0)
                        head++;
                }
                tmp += max(head, R - head);
            }
            ans = max(ans, tmp);
            for (int j = 0; j < R; j++) {
                if ((i >> j) & 1) {
                    for (int k = 0; k < C; k++) {
                        if (board[k][j] == 0)
                            board[k][j] = 1;
                        else
                            board[k][j] = 0;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 3380
final_rank: 13

code_snippet: //C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
int n,c,g[11][100001],tempg[11][100001];
int main(){
	while(1){
		cin >> n >> c;
		if(n==0 && c==0){
			return 0;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=c;j++){
				cin >> g[i][j];
			}
		}
		int ans=0,tans=0;
		for(int i=0;i<= 2<<n;i++){
			ans=0;
			memcpy(tempg,g,sizeof g);
			for(int j=1,k=i;j<=n;j++){
				if((k&1)==1){
					for(int l=1;l<=c;l++)tempg[j][l]=!tempg[j][l];
				}
				k=k>>1;
			}
			
			for(int j=1;j<=c;j++){
				int one=0,zero=0;
				for(int k=1;k<=n;k++){
					if(tempg[k][j]==1)one++;
					else if(tempg[k][j]==0)zero++;
				}
				ans+=max(one,zero);
			}
			tans=max(ans,tans);
		}
		cout << tans <<'\n';
	}

	return 0;
}
accuracy: 1
time_ms: 1790
memory_kb: 11584
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i, _n) for (int i = 0; i < (_n); i++)

bool bd[10][10000];
int R, C;
int res = 0;

void turnCol() {
    int tmp = 0;
    rep(j, C) {
        int oneCount = 0, zeroCount = 0;
        rep(i, R) {
            if (bd[i][j]) oneCount++;
            else zeroCount++;
        }
        tmp += max(oneCount, zeroCount);
    }
    res = max(res, tmp);
}

int main() {
    while (1) {
        cin >> R >> C;
        if (R == 0 && C == 0) break;

        rep(i, R) rep(j, C) {
            int tmp; cin >> tmp;
            bd[i][j] = tmp == 1 ? true : false;
        }

        int rs = 0;
        while (rs != (1 << (R + 1))) {
            bool backup[10][10000];
            memcpy(backup, bd, 100000);
            rep(i, R) {
                if ((1 << i) & rs) {
                    rep(j, C) bd[i][j] = !bd[i][j];
                }
            }
            turnCol();
            rs++;
            memcpy(bd, backup, 100000);
        }

        cout << res << endl;
    }
}
accuracy: 1
time_ms: 1130
memory_kb: 3244
final_rank: 18

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {}
  return 0;
}

int solve() {
  ll R, C;
  cin >> R >> C;
  if (R==0 and C==0) return 1;
  vv(ll, a, R, C);
  rep(i, R) rep(j, C) cin >> a[i][j];
  ll ans = 0;
  rep(mask, 1<<R) {
    ll total_cnt = 0;
    rep(j, C) {
      ll max_c = 0;
      rep(k, 2) {
        ll cnt = 0;
        rep(i, R) {
          cnt += ((a[i][j]^bit(mask,i)^k) == 0);
        }
        chmax(max_c, cnt);
      }
      total_cnt += max_c;
    }
    chmax(ans, total_cnt);
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 3892
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
int arr[11][1000000];
void solve(){
    int n,m;
    while(cin >> n >> m){
        int maxn=0;
        if(n==0||m==0) break;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin  >> arr[i][j];
            }
        }
        for(int s=0;s<=1<<n;s++){
            int ans=0;
            for(int j=0;j<m;j++){
                int cnt=0;
                for(int i=0;i<n;i++){
                    int x=1&(s>>i);
                    if(x^arr[i][j]) cnt++;
                }
                ans+=max(cnt,n-cnt);
            }
            maxn=max(ans,maxn);
        }
        cout << maxn << "\n";
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}
accuracy: 1
time_ms: 150
memory_kb: 21832
final_rank: 19