Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
p = [1]*100001
p[0] = p[1] = 0
for i in range(2,int(100001**0.5)+1):
    if p[i]:
        p[2*i::i] = [0]*len(p[2*i::i])
p = [i for i in range(100001) if p[i]]

while 1:
    m,a,b = map(int,raw_input().split())
    if m == 0: break
    
    aw = ah = 2
    mx = 4
    for w in p:
        for h in p:
            if w*h > m: break
            if w*h > mx and 1 >= w*1.0/h >= a*1.0/b:
                mx = w*h
                aw,ah = w,h
    print aw,ah            

Fixed submission:
import bisect
R = 100001/2
p = [1]*R
p[0] = p[1] = 0
for i in range(2,int(R**0.5)+1):
    if p[i]:
        p[2*i::i] = [0]*len(p[2*i::i])
p = [i for i in range(R) if p[i]]
n = len(p)
pxp = []
for i in range(n):
    for j in range(i,n):
        if p[i]*p[j] > 100000: break
        pxp.append([p[i]*p[j],p[i],p[j]])
pxp = sorted(pxp)
p,xyr = [e[0] for e in pxp],[[e[1],e[2],e[1]*1.0/e[2]] for e in pxp]
while 1:
    m,a,b = map(int,raw_input().split())
    if m == 0: break
    ab = a*1.0/b

    sp = bisect.bisect(p,m)
    for i in range(sp)[::-1]:
        if 1 >= xyr[i][2] >= ab:
            print xyr[i][0],xyr[i][1]
            break
Buggy python submission (verdict: Runtime Error):
for loop in range(int(raw_input())):
    manu = raw_input()
    msg = raw_input()
    size = len(msg)
    
    for s in manu[::-1]:
        if   s == "J":
            msg = msg[-1]+msg[:-1]
        elif s == "C":
            msg = msg[1:]+msg[0]
        elif s == "E":
            msg = msg[size/2+size%2:]+msg[:size/2]
        elif s == "A":
            msg = msg[::-1]
        elif s == "P":
            for i in range(len(msg)):
                if msg[i].isdigit():
                    msg = msg[:i]+str((int(msg[i])-1+10)%10)+msg[i+1:]
        elif s == "M":
            for i in range(len(msg)):
                if msg[i].isdigit():
                    msg = msg[:i]+str((int(msg[i])+1)%10)+msg[i+1:]
    
    print msg

Fixed submission:
for loop in range(int(raw_input())):
    manu = raw_input()
    msg = raw_input()
    size = len(msg)
    
    for s in manu[::-1]:
        if   s == "J":
            msg = msg[-1]+msg[:-1] if size > 1 else msg
        elif s == "C":
            msg = msg[1:]+msg[0] if size > 1 else msg
        elif s == "E":
            if size == 1: continue
            if size%2 == 0:
                msg = msg[size/2:]+msg[:size/2]
            else:
                msg = msg[size/2+1:]+msg[size/2]+msg[:size/2]
        elif s == "A":
            msg = msg[::-1]
        elif s == "P":
            for i in range(len(msg)):
                if msg[i].isdigit():
                    msg = msg[:i]+str((int(msg[i])-1+10)%10)+msg[i+1:]
        elif s == "M":
            for i in range(len(msg)):
                if msg[i].isdigit():
                    msg = msg[:i]+str((int(msg[i])+1)%10)+msg[i+1:]
    
    print msg

Buggy python submission (verdict: Runtime Error):
R = 2**15+1
dp = [[0]*R for i in range(4)]
for i in range(1,182):
	dp[0][i**2] += 1
for k in range(1,4):
	for i in range(1,182):
		for j in range(i**2,R-i**2):
			dp[k][j+i**2] += dp[k-1][j]

while 1:
	n = input()
	if n == 0: break
	print sum(dp[i][n] for i in range(4))

Fixed submission:
for loop in range(int(raw_input())):
    manu = raw_input()
    msg = raw_input()
    size = len(msg)
    
    for s in manu[::-1]:
        if   s == "J":
            msg = msg[-1]+msg[:-1] if size > 1 else msg
        elif s == "C":
            msg = msg[1:]+msg[0] if size > 1 else msg
        elif s == "E":
            if size == 1: continue
            if size%2 == 0:
                msg = msg[size/2:]+msg[:size/2]
            else:
                msg = msg[size/2+1:]+msg[size/2]+msg[:size/2]
        elif s == "A":
            msg = msg[::-1]
        elif s == "P":
            for i in range(len(msg)):
                if msg[i].isdigit():
                    msg = msg[:i]+str((int(msg[i])-1+10)%10)+msg[i+1:]
        elif s == "M":
            for i in range(len(msg)):
                if msg[i].isdigit():
                    msg = msg[:i]+str((int(msg[i])+1)%10)+msg[i+1:]
    
    print msg
Buggy python submission (verdict: Runtime Error):
r = 100001
p = [1]*r
p[0] = p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r,i)]
prime = []
for i in range(r):
	if p[i]: prime.append(i)
	
while 1:
	n = int(raw_input())
	if n == 0: break
	ans = 0
	i = 0
	while 1:
		s = 0
		j = i
		while 1:
			s += prime[j]
			if s >= n:
				if s == n:
					ans += 1
				else:
					break
			j += 1
		i += 1
		if i > n: break
	print ans

Fixed submission:
r = 100001
p = [1]*r
p[0] = p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r,i)]
prime = []
for i in range(r):
	if p[i]: prime.append(i)
	
while 1:
	n = int(raw_input())
	if n == 0: break
	ans = 0
	i = 0
	while 1:
		s = 0
		j = i
		while 1:
			s += prime[j]
			if s >= n:
				if s == n:
					ans += 1
				break
			j += 1
		i += 1
		if prime[i] > n: break
	print ans
Buggy python submission (verdict: Runtime Error):
r = 1500
p = [1]*r
p[0] = p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r,i)]
prime = []
for i in range(r):
	if p[i]: prime.append(i)

def solve(n,k,i):
	if k == 0: return 1 if n == 0 else 0
	if n-k*prime[i] < 0 : return 0
	res = 0
	res += solve(n-prime[i],k-1,i+1) + solve(n,k,i+1)
	return res

while 1:
	n,k = map(int,raw_input().split())
	if n == 0: break
	ans = 0
	for i in range(n):
		if k*prime[i] > n: break
		ans += solve(n-prime[i],k-1,i+1)
	print ans

Fixed submission:
r = 1121
p = [1]*r
p[0] = p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r,i)]
prime = []
for i in range(r):
	if p[i]: prime.append(i)

dp = [[0]*r for i in range(15)]
dp[0][0] = 1
for i in range(len(prime)):
	for k in range(min(i+1,14),0,-1):
		for j in range(prime[i],r):
			dp[k][j] += dp[k-1][j-prime[i]]

while 1:
	n,k = map(int,raw_input().split())
	if n == 0: break
	print dp[k][n]

Buggy python submission (verdict: Runtime Error):
r = 10000
p = [1]*r
p[0] = p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r,i)]
prime = []
for i in range(r):
	if p[i]: prime.append(i)

def solve(n,k,i):
	if k == 0: return 1 if n == 0 else 0
	if n-k*prime[i] < 0 : return 0
	return solve(n-prime[i],k-1,i+1) + solve(n,k,i+1)

while 1:
	n,k = map(int,raw_input().split())
	if n == 0: break
	ans = 0
	for i in range(n):
		if k*prime[i] > n: break
		ans += solve(n-prime[i],k-1,i+1)
	print ans

Fixed submission:
r = 1121
p = [1]*r
p[0] = p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r,i)]
prime = []
for i in range(r):
	if p[i]: prime.append(i)

dp = [[0]*r for i in range(15)]
dp[0][0] = 1
for i in range(len(prime)):
	for k in range(min(i+1,14),0,-1):
		for j in range(prime[i],r):
			dp[k][j] += dp[k-1][j-prime[i]]

while 1:
	n,k = map(int,raw_input().split())
	if n == 0: break
	print dp[k][n]
Buggy python submission (verdict: Runtime Error):
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0]*10
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1
        m = max(m,p)
    ans = 0.01
    for i in range(10):
        ans += (v[i]*1.0/max(v))*(1-i*1.0/m)
    print ans

Fixed submission:
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0.]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1.
        m = max(m,p)
    vm = max(v)
    ans = 0.01+sum((v[i]/vm)*(1-i*1.0/m) for i in range(m))
    print ans
Buggy python submission (verdict: Runtime Error):
while 1:
    n = int(raw_input())
    if n == 0: break
    ab = [raw_input().split() for i in xrange(n)]
    s = raw_input()
    g = raw_input()
    que = [[s,0]]
    while que:
        c,i = que.pop(0)
        if c == g:
            print i
            break
        for a,b in ab:
            cc = c.replace(a,b)
            if len(cc) > len(g): continue
            que.append([cc,i+1])
    else:
        print -1

Fixed submission:
while 1:
    n = int(raw_input())
    if n == 0: break
    ab = [raw_input().split() for i in xrange(n)]
    s = raw_input()
    g = raw_input()
    memo = set([s])
    que = [[s,0]]
    while que:
        c,i = que.pop(0)
        if c == g:
            print i
            break
        for a,b in ab:
            cc = c.replace(a,b)
            if len(cc) > len(g) or cc in memo: continue
            memo.add(cc)
            que.append([cc,i+1])
    else:
        print -1
Buggy python submission (verdict: Runtime Error):
while 1:
    n = int(raw_input())
    if n == 0: break
    exist = set([])
    enter = [0]*1000
    bless = [0]*1000
    for loop in xrange(n):
        md,hm,io,p = raw_input().split()
        h,m = map(int,hm.split(":"))
        t = 60*h+m
        p = int(p)
        if io == "I":
            time[p] = t
            exist.add(p)
        else:
            exist.remove(p)
            if p == 0:
                for i in exist: bless[i] += t-max(enter[p],enter[i])
            elif 0 in exist:
                bless[p] += t-max(enter[0],enter[p])
    print max(bless)
    

Fixed submission:
while 1:
    n = int(raw_input())
    if n == 0: break
    exist = set([])
    enter = [0]*1000
    bless = [0]*1000
    for loop in xrange(n):
        md,hm,io,p = raw_input().split()
        h,m = map(int,hm.split(":"))
        t = 60*h+m
        p = int(p)
        if io == "I":
            enter[p] = t
            exist.add(p)
        else:
            exist.remove(p)
            if p == 0:
                for i in exist: bless[i] += t-max(enter[p],enter[i])
            elif 0 in exist:
                bless[p] += t-max(enter[0],enter[p])
    print max(bless)
Buggy python submission (verdict: Time Limit Exceeded):
(N,M),B,P = [map(int,raw_input().split()) for i in xrange(3)]
C1 = []
for i in xrange(M): C1 += [1]*P[i] if i%2 else [0]*P[i]
C2 = [1-c for c in C1]

ans = 1e10
for C in [C1,C2]:
    if sum(B) == sum(C):
        tmp = 0
        i = j = 0
        while not i == j == N-1:
            if B[i] and C[j]:
                tmp += abs(i-j)
                i += 1; j += 1
            else:
                i += 1-B[i]; j += 1-C[i]
            i = min(N-1,i); j = min(N-1,j)
        ans = min(ans, tmp)
print ans

Fixed submission:
N,M = map(int,raw_input().split())
B = map(int,raw_input().split())
P = map(int,raw_input().split())
C1,C2 = [],[]
for i in xrange(M):
    C1 += [1]*P[i] if i%2 else [0]*P[i]
    C2 += [0]*P[i] if i%2 else [1]*P[i]

ans = 1e10
for C in [C1,C2]:
    if sum(B) == sum(C):
        tmp = 0
        i = j = 0
        while not i == j == N-1:
            if not B[i]: i = min(N-1, i+1)
            if not C[j]: j = min(N-1, j+1)
            if B[i] and C[j]:
                tmp += abs(i-j)
                i = min(N-1, i+1)
                j = min(N-1, j+1)
        ans = min(ans, tmp)
print ans
Buggy python submission (verdict: Runtime Error):
ref={"A":"BD","B":"ACE","C":"BF","D":"AEG","E":"BDFH","F":"CEI","G":"DH","H":"EGI","J":"HF"}
for i in range(1000):
	p=raw_input()
	for i in range(len(p)-1):
		if p[i+1] not in ref[p[i]]:
			break
	else:
		print p
	

Fixed submission:
ref={"A":"BD","B":"ACE","C":"BF","D":"AEG","E":"BDFH","F":"CEI","G":"DH","H":"EGI","I":"HF"}
for i in range(1000):
	p=raw_input()
	for i in range(len(p)-1):
		if p[i+1] not in ref[p[i]]:
			break
	else:
		print p
Buggy python submission (verdict: Runtime Error):
coins = [10,50,100,500]

while 1:
    cost = int(raw_input())
    if cost == 0: break
    c = map(int,raw_input().split())
    num = sum(c)

    mn = num
    ans = [0,0,0,0]
    for i in range(c[0]+1):
        for j in range(c[1]+1):
            for k in range(c[2]+1):
                for l in range(c[3]+1):
                    pay = 10*i+50*j+100*k+500*l
                    change = pay-cost
                    if change < 0: continue

                    tmp = [0,0,0,0]
                    for m in range(3,-1,-1):
                        while change-coins[m] >= 0:
                            change -= coins[m]
                            tmp[m] += 1
                    
                    for c1,c2 in zip([i,j,k,l],tmp):
                        if c1 > 0 and c2 > 0: break
                    else:
                        if num - (i+j+k+l) + sum(tmp) < mn:
                            mn = num - (i+j+k+l) + sum(tmp)
                            ans = [i,j,k,l]

    for ci,ki in zip(coins,ans):
        if ki == 0: continue
        print ci,ki
    print  

Fixed submission:
coins = (10,50,100,500)
isfirst = True
while 1:
    cost = int(raw_input())
    if cost == 0: break
    if not isfirst: print
    have = map(int,raw_input().split())

    budget = sum(i*j for i,j in zip(coins,have))
    change = budget-cost

    ret = [0]*4
    for i in reversed(range(4)):
        c = change/coins[i]
        ret[i] = c
        change -= c*coins[i]

    for i in range(4):
        if have[i]-ret[i] <= 0: continue
        print coins[i],have[i]-ret[i]

    isfirst = False
Buggy python submission (verdict: Runtime Error):
while 1:
	e = input()
	if e == 0: break
	ans = 3*e
	for z in range(e+1):
		z3 = z**3
		if z3 > e: break
		for y in range(e+1):
			y2 = y**2
			x = e - y2 - z3
			if x >= 0:
				ans = min(ans,x+y+z)
			else:
				break
	print ans

Fixed submission:
while 1:
	e = ans = input()
	if e == 0: break
	for z in range(e):
		z3 = z**3
		if z3 > e: break
		y = int((e-z3)**0.5)
		ans = min(ans,e+y+z-y**2-z3)
	print ans

Buggy python submission (verdict: Runtime Error):
while 1:
	e = input()
	if e == 0: break
	ans = 3*e
	for z in range(e+1):
		z3 = z**3
		if z3 > e: break
		for y in range(e+1):
			x = e - y**2 - z3
			if x >= 0:
				ans = min(ans,x+y+z)
			else:
				break
	print ans

Fixed submission:
while 1:
	e = ans = input()
	if e == 0: break
	for z in range(e):
		z3 = z**3
		if z3 > e: break
		y = int((e-z3)**0.5)
		ans = min(ans,e+y+z-y**2-z3)
	print ans

Buggy python submission (verdict: Runtime Error):
while 1:
	e = ans = input()
	if e == 0: break
	for z in range(e):
	    z3 = z**3
		if z3 > e: break
		y = int((e-z3)**0.5)
		ans = min(ans,e+y+z-y**2-z3)
	print ans

Fixed submission:
while 1:
	e = ans = input()
	if e == 0: break
	for z in range(e):
		z3 = z**3
		if z3 > e: break
		y = int((e-z3)**0.5)
		ans = min(ans,e+y+z-y**2-z3)
	print ans
Buggy python submission (verdict: Runtime Error):
def to_sec(a):
    h,m,s = map(int,a.split(":"))
    return 3600*h+60*m+s

while 1:
    n = int(raw_input())
    if n == 0: break
    used = [0]*84401
    for loop in range(n):
        a,b = raw_input().split()
        a,b = to_sec(a),to_sec(b)
        used[a] += 1
        used[b] -= 1
    for i in range(1,84400):
        used[i] += used[i-1]
    print max(used)

Fixed submission:
def to_sec(a):
    h,m,s = map(int,a.split(":"))
    return 3600*h+60*m+s

while 1:
    n = int(raw_input())
    if n == 0: break
    used = [0]*86401
    for loop in range(n):
        a,b = raw_input().split()
        a,b = to_sec(a),to_sec(b)
        used[a] += 1
        used[b] -= 1
    for i in range(1,86401):
        used[i] += used[i-1]
    print max(used)
Buggy python submission (verdict: Runtime Error):
def rec(x,y,c):
    if   A[y][x] == ".": A[y][x] = c
    elif A[y][x] != c  : A[y][x] = "x"
    for dx,dy in zip([1,0,-1,0],[0,1,0,-1]):
        nx,ny = x+dx,y+dy
        if 0 <= nx < w and 0 <= ny < h and A[ny][nx] in [".","b" if c == "w" else "w"]:
            rec(nx,ny,c)

while 1:
    w,h = map(int,raw_input().split())
    if w == 0: break
    A = [list(raw_input()) for _ in range(h)]
    for y in range(h):
        for x in range(w):
            if A[y][x] == "W": rec(x,y,"w")
            if A[y][x] == "B": rec(x,y,"b")
    print sum(Ai.count("b") for Ai in A),sum(Ai.count("w") for Ai in A)

Fixed submission:
import sys
sys.setrecursionlimit(3000)
def rec(x,y,c):
    if   A[y][x] == ".": A[y][x] = c
    elif A[y][x] != c  : A[y][x] = "x"
    for dx,dy in zip([1,0,-1,0],[0,1,0,-1]):
        nx,ny = x+dx,y+dy
        if 0 <= nx < w and 0 <= ny < h and A[ny][nx] in [".","b" if c == "w" else "w"]:
            rec(nx,ny,c)

while 1:
    w,h = map(int,raw_input().split())
    if w == 0: break
    A = [list(raw_input()) for _ in range(h)]
    for y in range(h):
        for x in range(w):
            if A[y][x] == "W": rec(x,y,"w")
            if A[y][x] == "B": rec(x,y,"b")
    print sum(Ai.count("b") for Ai in A),sum(Ai.count("w") for Ai in A)
Buggy python submission (verdict: Runtime Error):
while 1:
    N,M = map(int,raw_input().split())
    if N == 0: break
    h = [int(raw_input()) for _ in range(N)]
    w = [int(raw_input()) for _ in range(M)]
    ans = 0
    H,W = h[:],w[:]
    for i in range(N):
        s = h[i]
        for j in range(i+1,N):
            s += h[j]
            H.append(s)
    for i in range(M):
        s = w[i]
        for j in range(i+1,N):
            s += w[j]
            W.append(s)
    for hi in H:
        for wi in W:
                if hi == wi: ans += 1
    print ans

Fixed submission:
from collections import defaultdict

def getArray(a):
    d = defaultdict(int)
    n = len(a)
    for i in range(n):
        s = 0
        for j in range(i,n):
            s += a[j]
            d[s] += 1
    return d

while 1:
    N,M = map(int,raw_input().split())
    if N == 0: break
    h = [int(raw_input()) for _ in xrange(N)]
    w = [int(raw_input()) for _ in xrange(M)]
    H,W = getArray(h),getArray(w)
    print sum(H[hi]*W[hi] for hi in H)

Buggy python submission (verdict: Runtime Error):
while 1:
    N,M = map(int,raw_input().split())
    if N == 0: break
    h = [int(raw_input()) for _ in range(N)]
    w = [int(raw_input()) for _ in range(M)]
    ans = 0
    H,W = h[:],w[:]
    for i in range(N):
        s = h[i]
        for j in range(i+1,N):
            s += h[j]
            H.append(s)
    for i in range(M):
        s = w[i]
        for j in range(i+1,M):
            s += w[j]
            W.append(s)
    for hi in H:
        for wi in W:
                if hi == wi: ans += 1
    print ans

Fixed submission:
from collections import defaultdict

def getArray(a):
    d = defaultdict(int)
    n = len(a)
    for i in range(n):
        s = 0
        for j in range(i,n):
            s += a[j]
            d[s] += 1
    return d

while 1:
    N,M = map(int,raw_input().split())
    if N == 0: break
    h = [int(raw_input()) for _ in xrange(N)]
    w = [int(raw_input()) for _ in xrange(M)]
    H,W = getArray(h),getArray(w)
    print sum(H[hi]*W[hi] for hi in H)
Buggy python submission (verdict: Runtime Error):
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	E,B,Y = [],[],[]
	for i in range(n):
		era,base,year = raw_input().split()
		E.append(era)
		B.append(int(base))
		Y.append(int(year))
	for i in range(m):
		year = int(raw_input())
		for j in range(n):
			if Y[j]-B[j] < year <= Y[j]:
				print E[i], year-Y[j]+B[i]
				break
		else:
			print "Unknown"

Fixed submission:
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	EBY = [raw_input().split() for i in range(n)]
	EBY = [[e,int(y)-int(b),int(y)] for e,b,y in EBY]
	for i in range(m):
		year = int(raw_input())
		for j in range(n):
			if EBY[j][1] < year <= EBY[j][2]:
				print EBY[j][0], year-EBY[j][1]
				break
		else:
			print "Unknown"

Buggy python submission (verdict: Runtime Error):
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	E,B,Y = [],[],[]
	for i in range(n):
		era,base,year = raw_input().split()
		E.append(era)
		B.append(int(base))
		Y.append(int(year))
	for i in range(m):
		year = int(raw_input())
		for j in range(n):
			if Y[j]-B[j] < year <= Y[j]:
				print E[i], year-Y[j]+B[j]
				break
		else:
			print "Unknown"

Fixed submission:
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	EBY = [raw_input().split() for i in range(n)]
	EBY = [[e,int(y)-int(b),int(y)] for e,b,y in EBY]
	for i in range(m):
		year = int(raw_input())
		for j in range(n):
			if EBY[j][1] < year <= EBY[j][2]:
				print EBY[j][0], year-EBY[j][1]
				break
		else:
			print "Unknown"
Buggy python submission (verdict: Runtime Error):
while 1:
    t,n = map(int,raw_input().split())
    if t == n == 0: break
    block = [map(int,raw_input().split()) for _ in range(n)]
    sx,sy = map(int,raw_input().split())
    visited = []
    visited.append([sx,sy])
    que = [[sx,sy,t]]
    ans = 1
    while que:
        x,y,tt = que.pop(0)
        if tt == 0: continue
        for dx,dy in zip([1,1,0,-1,-1,0],[0,1,1,0,-1,-1]):
            nx,ny = x+dx,y+dy
            if [nx,ny] not in visited and [nx,ny] not in block:
                que.append([nx,ny,tt-1])
                visited.append([nx,ny])
                ans += 1
    print ans

Fixed submission:
while 1:
    t,n = map(int,raw_input().split())
    if t == n == 0: break
    block = []
    for loop in range(n):
        x,y = map(int,raw_input().split())
        block.append((x+100,y+100))
    sx,sy = map(int,raw_input().split())
    sx += 100; sy += 100
    visited = [[False]*200 for _ in range(200)]
    visited[sy][sx] = True
    que = [[sx,sy,t]]
    ans = 1
    while que:
        x,y,tt = que.pop(0)
        if tt == 0: continue
        for dx,dy in zip([1,1,0,-1,-1,0],[0,1,1,0,-1,-1]):
            nx,ny = x+dx,y+dy
            if not visited[ny][nx] and (nx,ny) not in block:
                que.append([nx,ny,tt-1])
                visited[ny][nx] = True
                ans += 1
    print ans
Buggy python submission (verdict: Runtime Error):
print max([sum(map(int,raw_input().split())) for i in range(map(int,raw_input().split())[0])]

Fixed submission:
print max([sum(map(int,raw_input().split())) for i in range(map(int,raw_input().split())[0])])
Buggy python submission (verdict: Runtime Error):
print min(raw_input().count(i) for i in "KUPC")

Fixed submission:
a = raw_input()
print min(a.count(i) for i in "KUPC")
Buggy python submission (verdict: Runtime Error):
while 1:
    n = int(raw_input())
    if n == 0: break
    L = [0]*n
    D = [0]*n
    for man in xrange(n):
        m,l = map(int,raw_input().split())
        L[man] = l
        t = 0
        for date in xrange(m):
            s,e = map(int,raw_input().split())
            t ^= ((1 << (e-6))-1) ^ ((1 << (s-6))-1)
        D[man] = t
    dp = [[0]*(1 << 17) for i in xrange(n)]
    dp[0][D[0]] = L[0]
    for i in xrange(1,n):
        for bit in xrange(1 << 17):
            if dp[i-1][bit] and bit&D[i] == 0:
                dp[i][bit|D[i]] = max(dp[i][bit|D[i]], dp[i-1][bit]+L[i])
        dp[i][D[i]] = max(dp[i][D[i]], L[i])
    print max(max(dp[i]) for i in xrange(n))

Fixed submission:
from collections import defaultdict
while 1:
    n = int(raw_input())
    if n == 0: break
    L = [0]*n
    T = [0]*n
    for man in xrange(n):
        m,l = map(int,raw_input().split())
        L[man] = l
        t = 0
        for date in xrange(m):
            s,e = map(int,raw_input().split())
            t |= 2**(e-6)-2**(s-6)
        T[man] = t

    dp = defaultdict(int)
    for l,t in zip(L,T):
        for bit in dp.keys():
            if bit&t == 0:
                dp[bit|t] = max(dp[bit|t], dp[bit]+l)
        dp[t] = max(dp[t], l)
        
    print max(dp.values())
Buggy python submission (verdict: Runtime Error):
def fact(n):
	return 1 if n == 0 else n*fact(n-1)

S = raw_input()
l,s = len(S),set(list(S))
lens = len(s)
d = [S.count(i) for i in s]
if l%2 == 0:
	for i in range(lens):
		if d[i]%2 == 1:
			print 0
			break
	else:
		denomi = 1
		for i in range(lens):
			denomi *= fact(d[i]/2)
		print fact(l/2)/denomi
else:
	for i in range(m):
		if sum([d[i]%2 for i in range(lens)]) != 1:
			print 0
			break
	else:
		denomi = 1
		for i in range(lens):
			denomi *= fact(d[i]/2) if d[i]%2 == 0 else fact((d[i]-1)/2)
		print fact((l-1)/2)/denomi

Fixed submission:
from math import factorial as f
S = raw_input()
L = len(S)
d = [S.count(i) for i in set(list(S))]
dd = sum([i%2 for i in d])
if (L%2 == 0 and dd != 0 ) or (L%2 == 1 and dd != 1): 
		print 0
else:
	ans = f(L/2)
	for i in d:
		ans /= f(i/2)
	print ans