Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x=[0,0,0,0,0,0,1,2,3,-1,-2,-3]
y=[1,2,3,-1,-2,-3,0,0,0,0,0,0]

def dfs(ty,tx):
    if L[ty][tx]==1:
        L[ty][tx]=0
        for i,j in zip(x,y):
            dx,dy=tx+i,ty+j
            if 0<=dx<8 and 0<=dy<8:
                dfs(dy,dx)
    else:
        return

n=input()
for i in range(n):
    L=[map(int,raw_input()) for j in range(8)]
    ax,ay=input(),input()
    dfs(ay-1,ax-1)
    print "Data %d:"%(i+1)
    for j in range(8):
        print "".join(map(str,L[j]))

Fixed submission:
x=[0,0,0,0,0,0,1,2,3,-1,-2,-3]
y=[1,2,3,-1,-2,-3,0,0,0,0,0,0]

def dfs(ty,tx):
    if L[ty][tx]==1:
        L[ty][tx]=0
        for i,j in zip(x,y):
            dx,dy=tx+i,ty+j
            if 0<=dx<=7 and 0<=dy<=7:
                dfs(dy,dx)
    return

n=input()
for i in range(n):
    skip=raw_input()
    L=[map(int,raw_input()) for j in range(8)]
    ax,ay=input(),input()
    dfs(ay-1,ax-1)
    print "Data %d:"%(i+1)
    for j in range(8):
        print "".join(map(str,L[j]))

Buggy python submission (verdict: Runtime Error):
x=[0,0,0,0,0,0,1,2,3,-1,-2,-3]
y=[1,2,3,-1,-2,-3,0,0,0,0,0,0]

def dfs(ty,tx):
    if L[ty][tx]==1:
        L[ty][tx]=0
        for i,j in zip(x,y):
            dx,dy=tx+i,ty+j
            if 0<=dx<8 and 0<=dy<8:
                dfs(dy,dx)
    return

n=input()
for i in range(n):
    L=[map(int,raw_input()) for j in range(8)]
    ax,ay=input(),input()
    dfs(ay-1,ax-1)
    print "Data %d:"%(i+1)
    for j in range(8):
        print "".join(map(str,L[j]))

Fixed submission:
x=[0,0,0,0,0,0,1,2,3,-1,-2,-3]
y=[1,2,3,-1,-2,-3,0,0,0,0,0,0]

def dfs(ty,tx):
    if L[ty][tx]==1:
        L[ty][tx]=0
        for i,j in zip(x,y):
            dx,dy=tx+i,ty+j
            if 0<=dx<=7 and 0<=dy<=7:
                dfs(dy,dx)
    return

n=input()
for i in range(n):
    skip=raw_input()
    L=[map(int,raw_input()) for j in range(8)]
    ax,ay=input(),input()
    dfs(ay-1,ax-1)
    print "Data %d:"%(i+1)
    for j in range(8):
        print "".join(map(str,L[j]))

Buggy python submission (verdict: Runtime Error):
x=[0,0,0,0,0,0,1,2,3,-1,-2,-3]
y=[1,2,3,-1,-2,-3,0,0,0,0,0,0]

def dfs(ty,tx):
    if L[ty][tx]==1:
        L[ty][tx]=0
        for i,j in zip(x,y):
            dx,dy=tx+i,ty+j
            if 0<=dx<=7 and 0<=dy<=7:
                dfs(dy,dx)
    return

n=input()
for i in range(n):
    L=[map(int,raw_input()) for j in range(8)]
    ax,ay=input(),input()
    dfs(ay-1,ax-1)
    print "Data %d:"%(i+1)
    for j in range(8):
        print "".join(map(str,L[j]))

Fixed submission:
x=[0,0,0,0,0,0,1,2,3,-1,-2,-3]
y=[1,2,3,-1,-2,-3,0,0,0,0,0,0]

def dfs(ty,tx):
    if L[ty][tx]==1:
        L[ty][tx]=0
        for i,j in zip(x,y):
            dx,dy=tx+i,ty+j
            if 0<=dx<=7 and 0<=dy<=7:
                dfs(dy,dx)
    return

n=input()
for i in range(n):
    skip=raw_input()
    L=[map(int,raw_input()) for j in range(8)]
    ax,ay=input(),input()
    dfs(ay-1,ax-1)
    print "Data %d:"%(i+1)
    for j in range(8):
        print "".join(map(str,L[j]))
Buggy python submission (verdict: Runtime Error):
merry=[4,1,4,1,2,1,2,1]
while True:
    try:
        guest=map(int,raw_input().split())
    except EOFError:
        break
    m=10000
    for i in range(len(merry)):
        temp=merry[i:]+merry[:i]
        s=sum([guest[i]-temp[i] for i in range(len(merry)) if guest[i]-temp[i]>\
=0])
        m=min(m,s)
    P=set([])
    for i in range(len(merry)):
        temp=merry[i:]+merry[:i]
        s=sum([guest[i]-temp[i] for i in range(len(merry)) if guest[i]-temp[i]>\
=0])
        if s==m:
            P.add(int("".join(map(str,temp))))
    print " ".join(list(str(min(P))))

Fixed submission:
c=[4,1,4,1,2,1,2,1]
while True:
    try:
        p=map(int,raw_input().split())
    except EOFError:
        break
    m,ans=100000000,"9"*10
    for i in range(len(c)):
        t=c[i:]+c[:i]
        s=sum([p[i]-t[i] for i in range(len(c)) if p[i]>t[i]])
        if (s<m) or (s==m and int(ans)>int("".join(map(str,t)))):
            m=s
            ans="".join(map(str,t))
    print " ".join(ans)

Buggy python submission (verdict: Runtime Error):
merry=[4,1,4,1,2,1,2,1]
while True:
    try:
        gst=map(int,raw_input().split())
    except EOFError:
        break
    m=10000
    ans=set()
    for i in range(len(merry)):
        temp=merry[i:]+merry[:i]
        s=sum([gst[i]-temp[i] for i in range(len(merry)) if gst[i]>temp[i]])
        if s<m:
            m=s
            ans.clear()
            ans.add("".join(map(str,temp)))
        if s==m:
            ans.add("".join(map(str,temp)))
    print " ".join(min(ans))

Fixed submission:
c=[4,1,4,1,2,1,2,1]
while True:
    try:
        p=map(int,raw_input().split())
    except EOFError:
        break
    m,ans=100000000,"9"*10
    for i in range(len(c)):
        t=c[i:]+c[:i]
        s=sum([p[i]-t[i] for i in range(len(c)) if p[i]>t[i]])
        if (s<m) or (s==m and int(ans)>int("".join(map(str,t)))):
            m=s
            ans="".join(map(str,t))
    print " ".join(ans)

Buggy python submission (verdict: Runtime Error):
merry=[4,1,4,1,2,1,2,1]
while True:
    try:
        gst=map(int,raw_input().split())
    except EOFError:
        break
    m=10000
    ans=set()
    for i in range(len(merry)):
        temp=merry[i:]+merry[:i]
        s=sum([max(gst[i]-temp[i],0) for i in range(len(merry))])
        if s==m:
            ans.add("".join(map(str,temp)))
        elif s<m:
            m=s
            ans.clear()
            ans.add("".join(map(str,temp)))
    print " ".join(min(ans))

Fixed submission:
c=[4,1,4,1,2,1,2,1]
while True:
    try:
        p=map(int,raw_input().split())
    except EOFError:
        break
    m,ans=100000000,"9"*10
    for i in range(len(c)):
        t=c[i:]+c[:i]
        s=sum([p[i]-t[i] for i in range(len(c)) if p[i]>t[i]])
        if (s<m) or (s==m and int(ans)>int("".join(map(str,t)))):
            m=s
            ans="".join(map(str,t))
    print " ".join(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    cnt=0
    for i in itertools.combinations(range(101),n):
        if len(set(i))==n and sum(i)==s:
            cnt+=1
    print cnt

Fixed submission:
dp=[[0]*1001 for i in range(11)]
dp[0][0]=1
for i in range(101):
    for j in range(10)[::-1]:
        for k in range(1001-i):
            dp[j+1][k+i]+=dp[j][k]
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    print dp[n][s]

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    cnt=0
    for i in itertools.combinations(range(101),n):
        if len(set(i))==n and sum(i)==s:
            cnt+=1
        if i[0]>=s:break
    print cnt

Fixed submission:
dp=[[0]*1001 for i in range(11)]
dp[0][0]=1
for i in range(101):
    for j in range(10)[::-1]:
        for k in range(1001-i):
            dp[j+1][k+i]+=dp[j][k]
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    print dp[n][s]

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    cnt=0
    for i in itertools.combinations(range(101),n):
        if sum(i)==s:
            cnt+=1
        if i[0]>=s:break
    print cnt

Fixed submission:
dp=[[0]*1001 for i in range(11)]
dp[0][0]=1
for i in range(101):
    for j in range(10)[::-1]:
        for k in range(1001-i):
            dp[j+1][k+i]+=dp[j][k]
while True:
    n,s=map(int,raw_input().split())
    if n==s==0:break
    print dp[n][s]
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,raw_input().split())
L=[0]*n
for i in range(q):
    a,v=map(int,raw_input().split())
    L[a-1]+=v
    m=max(L)
    print L.index(m)+1,m

Fixed submission:
from collections import defaultdict
n,q=map(int,raw_input().split())
va=defaultdict(set)
av=defaultdict(int)
for i in range(q):
    a,v=map(int,raw_input().split())
    try:
        va[av[a]].remove(a)
        if va[av[a]]==set([]):
            del va[av[a]]
    except KeyError:
        pass
    av[a]+=v
    va[av[a]].add(a)
    m=max(va.keys())
    t=min(va[m])
    print t,m
Buggy python submission (verdict: Runtime Error):
mv=((2,0),(2,1),(2,-1),(-2,0),(-2,1),(-2,-1),
    (0,2),(1,2),(-1,2),(0,-2),(1,-2),(-1,-2))

while True:
    x,y=map(int,raw_input().split())
    if x==y==0:break
    n=input()
    pos=map(int,raw_input().split())
    pos=[(pos[2*i],pos[2*i+1]) for i in range(n)]

    que=[(x,y,0)]
    while que!=[]:
        X,Y,p=que[0][0],que[0][1],que[0][2]
        del que[0]
        S=set()
        if p>=10:
            print "OK"
            break
        for k in range(-1,2):
            for l in range(-1,2):
                S.add((pos[p][0]+k,pos[p][1]+l,p+1))
        for dx,dy in mv:
            mx=X+dx
            my=Y+dy
            if 0<=mx<10 and 0<=my<10 and (mx,my,p+1) in S:
                que.append((mx,my,p+1))
    else:
        print "NA"

Fixed submission:
mv=((2,0),(2,1),(2,-1),(-2,0),(-2,1),(-2,-1),
    (0,2),(1,2),(-1,2),(0,-2),(1,-2),(-1,-2))

while True:
    x,y=map(int,raw_input().split())
    if x==y==0:break
    n=input()
    pos=map(int,raw_input().split())
    pos=[(pos[2*i],pos[2*i+1]) for i in range(n)]

    que=[(x,y,0)]
    while que!=[]:
        X,Y,p=que[0][0],que[0][1],que[0][2]
        del que[0]
        S=set()
        if p>=n:
            print "OK"
            break
        for k in range(-1,2):
            for l in range(-1,2):
                S.add((pos[p][0]+k,pos[p][1]+l,p+1))
        for dx,dy in mv:
            mx=X+dx
            my=Y+dy
            if 0<=mx<10 and 0<=my<10 and (mx,my,p+1) in S:
                que.append((mx,my,p+1))
    else:
        print "NA"
Buggy python submission (verdict: Runtime Error):
import itertools
dic={"61":"z","62":".","63":"?","64":"!","65":" "}
cnt=ord("a")
for i in itertools.product(range(1,6),repeat=2):
    dic["".join(map(str,i))]=chr(cnt)
    cnt+=1

while True:
    try:
        s=raw_input()
    except EOFError:
        break
    if len(s)%2!=0:
        print "NA"
    else:
        print "".join(dic[s[i:i+2]] for i in range(0,len(s),2))

Fixed submission:
import itertools
dic={"61":"z","62":".","63":"?","64":"!","65":" "}
cnt=ord("a")
for i in itertools.product(range(1,6),repeat=2):
    dic["".join(map(str,i))]=chr(cnt)
    cnt+=1

while True:
    try:
        s=raw_input()
    except EOFError:
        break
    if len(s)%2!=0:
        print "NA"
    else:
        try:
            print "".join(dic[s[i:i+2]] for i in range(0,len(s),2))
        except KeyError:
            print "NA"
Buggy python submission (verdict: Runtime Error):
n=input()
for i in range(n):
    hh,mm=map(int,raw_input().split(":"))
    angleh=(60*hh+mm)*0.5
    anglem=6*mm
    diff=math.abs(angleh-anglem)
    if 0<=diff<30:
        print "alert"
    elif 90<=diff<=180:
        print "safe"
    else:
        print "warning"

Fixed submission:
n=input()
for i in range(n):
    hh,mm=map(int,raw_input().split(":"))
    angleh=(60*hh+mm)*0.5
    anglem=6*mm
    diff=abs(angleh-anglem)
    if diff>180:diff=360-diff
    if 0<=diff<30:
        print "alert"
    elif 90<=diff<=180:
        print "safe"
    else:
        print "warning"
Buggy python submission (verdict: Time Limit Exceeded):
import math
N=1000000
prime=[1]*(N+1)
prime[0]=0
prime[1]=0
for i in range(2,int(math.sqrt(N))):
    if prime[i]==1:
        j=i
        while i*j<=N:
            prime[i*j]=0
            j+=1

while True:
    n=input()
    if n==0:break
    cnt=0
    for i in range(n):
        p,m=map(int,raw_input().split())
        for j in range(max(p-m,0),min(p+m+1,N+1)):
            if prime[j]==1:
                cnt+=1
    print cnt-n

Fixed submission:
import math
import bisect
N=1000000
prime=[1]*(N+1)
prime[0]=0
prime[1]=0
for i in range(2,int(math.sqrt(N))):
    if prime[i]==1:
        j=i
        while i*j<=N:
            prime[i*j]=0
            j+=1
prime=[i for i in range(N+1) if prime[i]==1]

while True:
    n=input()
    if n==0:break
    cnt=0
    for i in range(n):
        p,m=map(int,raw_input().split())
        l=bisect.bisect_left(prime,p-m)
        u=bisect.bisect_left(prime,p+m+1)
        cnt+=u-l
    print cnt-n

Buggy python submission (verdict: Time Limit Exceeded):
import math
N=1000000
prime=[1]*(N+1)
prime[0]=0
prime[1]=0
for i in range(2,int(math.sqrt(N))):
    if prime[i]==1:
        j=i
        while i*j<=N:
            prime[i*j]=0
            j+=1
prime=[i for i in range(N+1) if prime[i]==1]

while True:
    n=input()
    if n==0:break
    cnt=0
    for i in range(n):
        p,m=map(int,raw_input().split())
        for j in range(len(prime)):
            if p-m<=prime[j]<=p+m:
                cnt+=1
            if p+m<=prime[j]:
                break
    print cnt-n

Fixed submission:
import math
import bisect
N=1000000
prime=[1]*(N+1)
prime[0]=0
prime[1]=0
for i in range(2,int(math.sqrt(N))):
    if prime[i]==1:
        j=i
        while i*j<=N:
            prime[i*j]=0
            j+=1
prime=[i for i in range(N+1) if prime[i]==1]

while True:
    n=input()
    if n==0:break
    cnt=0
    for i in range(n):
        p,m=map(int,raw_input().split())
        l=bisect.bisect_left(prime,p-m)
        u=bisect.bisect_left(prime,p+m+1)
        cnt+=u-l
    print cnt-n
Buggy python submission (verdict: Runtime Error):
import math

def inputData(j):
    A=[]
    t=0
    for i in range(j-1):
        v=input()
        x=math.cos(math.pi*(v+t)/180)
        y=math.sin(math.pi*(v+t)/180)
        t+=v
        A.append((x,y))
    A.append(A[0])
    return A

def calcArea(A):
    return sum((A[i][0]-A[i+1][0])*(A[i][1]+A[i+1][1]) for i in range(m-1))/2

while True:
    m=input()
    if m==0:break
    A=inputData(m)
    n=input()
    B=inputData(n)
    S1,S2=calcArea(A),calcArea(B)
    if S1>S2:
        print 1
    elif S1<S2:
        print 2
    else:
        print 0

Fixed submission:
import math

def area(n):
    S,r,t=0,10,0
    for i in range(n):
        if i==n-1:
            v=360-t
        else:
            v=input()
            t+=v
        S+=r*r*math.sin(math.pi*v/180)/2
    return S

while True:
    m=input()
    if m==0:break
    S1=area(m)
    n=input()
    S2=area(n)
    if S1>S2:
        print 1
    elif S1<S2:
        print 2
    else:
        print 0
Buggy python submission (verdict: Runtime Error):
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[tupl\
e(range(0,9,4))]+[tuple(range(2,7,2))]
    for i,j,k in L:
        if s[i]==s[j]==s[k]:
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"

Fixed submission:
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[(0,4\
,8),(2,4,6)]
    for i,j,k in L:
        if s[i]==s[j]==s[k]!="+":
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"

Buggy python submission (verdict: Runtime Error):
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    L=[(i,i+1,i+2) for i in range(0,9,3)]+
    [(i,i+3,i+6) for i in range(3)]+
    [(0,4,8),(2,4,6)]
    for i,j,k in L:
        if s[i]==s[j]==s[k]:
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"

Fixed submission:
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[(0,4\
,8),(2,4,6)]
    for i,j,k in L:
        if s[i]==s[j]==s[k]!="+":
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"
Buggy python submission (verdict: Runtime Error):
while True:
    L=input()
    if L=0:break
    flag=True
    for i in range(1,13):
        M,N=map(int,raw_input().split())
        L-=(M-N)
        if L<=0 and flag:
            print i
            flag=False
    else:
        print "NA"

Fixed submission:
while True:
    L=input()
    if L==0:break
    T=[]
    for i in range(1,13):
        M,N=map(int,raw_input().split())
        T.append(M-N)
    for i in range(1,13):
        L-=T[i-1]
        if L<=0:
            print i
            break
    else:
        print "NA"
Buggy python submission (verdict: Runtime Error):
while True:
    n=input()
    if n==0:break
    D={}
    m=0
    for i in range(n):
        p,d1,d2=map(int,raw_input().split())
        t=d1+d2
        m=max(m,t)
        D[t]=p
    print D[m],m

Fixed submission:
while True:
    try:
        n=input()
        if n==0:break
        m=0
        dic={}
        for i in range(n):
            p,d1,d2=map(int,raw_input().split())
            t=d1+d2
            m=max(m,t)
            dic[t]=p
        print dic[m],m
    except SyntaxError:
        pass

Buggy python submission (verdict: Runtime Error):
while True:
    n=input()
    if n==0:break
    m=0
    dic={}
    for i in range(n):
       p,d1,d2=map(int,raw_input().split())
       t=d1+d2
       m=max(m,t)
       dic[t]=p
    print dic[m],m

Fixed submission:
while True:
    try:
        n=input()
        if n==0:break
        m=0
        dic={}
        for i in range(n):
            p,d1,d2=map(int,raw_input().split())
            t=d1+d2
            m=max(m,t)
            dic[t]=p
        print dic[m],m
    except SyntaxError:
        pass
Buggy python submission (verdict: Runtime Error):
while True:
    n=input()
    if n==0:break
    L=[0]*10
    for i in range(n):
        L[input()]+=1
    for i in range(10):
        print "*"*L[i] if L[i]!=0 else "-"

Fixed submission:
while True:
    try:
        n=input()
        if n==0:break
        L=[0]*10
        for i in range(n):
            L[input()]+=1
        for i in range(10):
            print "*"*L[i] if L[i]!=0 else "-"
    except SyntaxError:pass
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,raw_input().split())
C=set(map(int,raw_input().split()))
for i in range(Q):
    q=input()
    print max(map(lambda x:x%q,C))

Fixed submission:
N,Q=map(int,raw_input().split())
A=map(int,raw_input().split())
maxA=max(A)
T=[0]*(maxA+2)
for i in A:
    T[i]=1
L=[0]*(maxA+2)
num=0
for i in range(maxA+2):
    L[i]=num
    if T[i]==1:
        num=i
for i in range(Q):
    q=input()
    maxv=0
    cur=maxA
    while True:
        p=cur%q
        maxv=max(maxv,p)
        if cur-p<=0: break
        cur=L[cur-p]
    print maxv
Buggy python submission (verdict: Time Limit Exceeded):
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    ma=0
    for i in range(n-k+1):
        ma=max(sum(L[i:i+k]),ma)
    print ma

Fixed submission:
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    maxInt=-10000000
    temp=sum(L[:k])
    for i in range(k,n):
        maxInt=max(maxInt,temp)
        temp=temp+L[i]-L[i-k]
    print maxInt

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    print sorted(sum(L[i:i+k]) for i in range(n-k+1))[-1]

Fixed submission:
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    maxInt=-10000000
    temp=sum(L[:k])
    for i in range(k,n):
        maxInt=max(maxInt,temp)
        temp=temp+L[i]-L[i-k]
    print maxInt

Buggy python submission (verdict: Runtime Error):
#include <stdio.h>
int main(){
  int i,n,k,s;
  while (1){
    int ma=0;
    scanf("%d %d",&n,&k);
    if (n==0 && k==0)break;
    int a[n];
    for (i=0;i<n;i++)
      scanf("%d",&a[i]);
    for (i=0;i<n-2;i++){
      s=a[i]+a[i+1]+a[i+2];
      if (s>ma) ma=s;
    }
    printf("%d\n",ma);
  }
  return 0;
}

Fixed submission:
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    maxInt=-10000000
    temp=sum(L[:k])
    for i in range(k,n):
        maxInt=max(maxInt,temp)
        temp=temp+L[i]-L[i-k]
    print maxInt

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    maxInt=-100000
    for i in range(n-k):
        maxInt=max(maxInt,sum(L[i:i+k]))
    print maxInt

Fixed submission:
while True:
    n,k=map(int,raw_input().split())
    if n==k==0:break
    L=[input() for i in range(n)]
    maxInt=-10000000
    temp=sum(L[:k])
    for i in range(k,n):
        maxInt=max(maxInt,temp)
        temp=temp+L[i]-L[i-k]
    print maxInt
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from copy import deepcopy

def turnOverRow(now_state,combs,c):
    for i in combs:
        for j in range(c):
            now_state[i][j]=0 if now_state[i][j]==1 else 1

def turnOverCol(now_state,r,c):
    h=r/2
    for i in range(c):
        cnt=0
        for j in range(r):
            if now_state[j][i]==1:
                cnt+=1
        if cnt>h:
            for j in range(r):
                now_state[j][i]=1 if now_state[j][i]==0 else 0

def countMax(now_state,r):
    return sum(sum(now_state[i]) for i in range(r))

while True:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    init_state=[map(int,raw_input().split()) for i in range(r)]
    now_state=deepcopy(init_state)
    ans=10000000000
    for i in range(r+1):
        for combs in itertools.combinations(range(r),i):
            turnOverRow(now_state,combs,c)
            turnOverCol(now_state,r,c)
            ans=min(ans,countMax(now_state,r))
            now_state=deepcopy(init_state) #initialization
    print r*c-ans

Fixed submission:
while True:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    state=[raw_input().split() for i in range(r)]
    state=map(list,zip(*state))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            n=bin(i^j).count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print ans

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    state=[raw_input().split() for i in range(r)]
    state=map(list,zip(*state))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            b=format(i^j,"b")
            n=b.count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print ans

Fixed submission:
while True:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    state=[raw_input().split() for i in range(r)]
    state=map(list,zip(*state))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            n=bin(i^j).count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print ans