Title: おせんべい

Problem:
IOI Seika has been using traditional methods to bake senbei (rice crackers) since its establishment. This traditional method involves baking one side over charcoal for a certain time, then flipping it to bake the other side for an equal amount of time. While adhering to this tradition, the senbei are baked using a machine. The machine arranges the senbei in a rectangular shape with R (1 ≤ R ≤ 10) rows and C (1 ≤ C ≤ 10000) columns. Normally, the machine operates automatically, flipping the senbei all at once after one side is baked to proceed with baking the other side over charcoal.

One day, during the process of baking, an earthquake occurred just before flipping the senbei, causing some of them to flip prematurely. Fortunately, the charcoal remained at the appropriate temperature. However, further baking the top side would exceed the traditional baking time, making the senbei unsuitable for shipment. To address this, the machine was quickly switched to manual operation to flip only the senbei that had not yet been flipped. The machine can flip several rows simultaneously or several columns simultaneously, but unfortunately, it cannot flip one senbei at a time.

To prevent the unsuitable baking of the unflipped senbei, the decision was made to flip several rows at once, followed by flipping several columns at once, ensuring that both sides are baked without exceeding the appropriate time. The goal is to maximize the number of senbei that can be shipped, referred to as "shippable senbei." It is also considered that no rows or columns need to be flipped. Write a program to output the maximum number of shippable senbei.

After the earthquake, the senbei were in the following state, with black circles representing the baked top side and white circles representing the baked bottom side.

[Image: Senbei State]

Flipping the first row results in the following state.

[Image: Senbei State After Flipping First Row]

Furthermore, flipping the 1st and 5th columns results in a state where 9 senbei can be shipped.

[Image: Senbei State After Flipping Columns]

Hint:
Note that the upper limit of R (10) is smaller than the upper limit of C (10000).

Input:
The input consists of multiple datasets. Each dataset is given in the following format. The first line of input contains two integers R, C (1 ≤ R ≤ 10, 1 ≤ C ≤ 10000) separated by a space. The following R lines represent the state of the senbei after the earthquake. The (i+1)th line (1 ≤ i ≤ R) contains C integers separated by spaces, where a<sub>i,j</sub> represents the state of the senbei at row i and column j. If a<sub>i,j</sub> is 1, it indicates that the top side is baked, and if it is 0, it indicates that the bottom side is baked.

When both C and R are 0, it indicates the end of the input. The number of datasets does not exceed 5.

Output:
For each dataset, output the maximum number of shippable senbei on a single line.

Input/Output Example:
Input:
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

Output:
9
15

# Buggy version:
for e in iter(input,'0 0'):
 r,_=map(int,e.split())
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=min(c,r-c)
  a=max(a,b)
 print(a)


# Fixed version:
for e in iter(input,'0 0'):
 r,_=map(int,e.split())
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=max(c,r-c)
  a=max(a,b)
 print(a)

# Buggy version:
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x))for x in zip(*[input().split()for _ in[0]*r])]
 a=[]
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2 else r-c
  a+=[b]
 print(max(a))


# Fixed version:
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=[]
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2 else r-c
  a+=[b]
 print(max(a))

# Buggy version:
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 b=1<<r
 c=[1]*b
 for m in range(b):
  if c[m]:
   c[~m]=0
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=c if c>r//2 else r-c
   if a<t:a=t
 print(a)


# Fixed version:
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for m in range(1<<~-r):
  t=0
  for s in d:
   c=bin(m^s).count('1')
   t+=c if c>r//2 else r-c
  if a<t:a=t
 print(a)