Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
c=0
for W in iter(input,'0\n'):
 c+=1
 W=int(W)
 dp=[0]*-~W
 for _ in[0]*int(input()):
  v,w=map(int,input().split(','))
  for i in range(W,w-1,-1):
   if dp[i]<dp[i-w]+v:dp[i]=dp[i-w]+v
 for i in range(W+1):
  if dp[W]==dp[i]:print(f'Case {c}:\n{dp[W]}\n{i}');break


Fixed submission:
def f():
 c=0
 for W in iter(input,'0'):
  c+=1
  W=int(W)
  d=[0]*-~W
  for _ in[0]*int(input()):
   v,w=map(int,input().split(','))
   for i in range(W,w-1,-1):
    if d[i]<d[i-w]+v:d[i]=d[i-w]+v
  print(f'Case {c}:\n{d[W]}\n{d.index(d[W])}')
f()
Buggy python submission (verdict: Runtime Error):
import sys
def f(c,h=0):
 if 2 in c and sum(c)==2:return 1
 if 5 in c:return 0  # sum(c)==2
 if 4 in c:
     k=c.index(4);c[k]-=3
     if f(c,h+1):return 1
     c[k]+=3
 if 3 in c:
     k=c.index(3);c[k]-=3
     if f(c,h+1):return 1
     c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
      c[i]-=1;c[i+1]-=1;c[i+2]-=1
      if f(c,h+1):return 1
      c[i]+=1;c[i+1]+=1;c[i+2]+=1
n='123456789'
for e in sys.stdin:
 e=list(e)
 a=[i for i in n if f([(e+[i]).count(j)for j in n])]
 print(*a if a else 0)


Fixed submission:
import sys
def f(c):
 if sum(c)in c:return 1
 if 5 in c:return 0
 if 4 in c:
  k=c.index(4);c[k]-=3
  if f(c):return 1
  c[k]+=3
 if 3 in c:
  k=c.index(3);c[k]-=3
  if f(c):return 1
  c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
   c[i]-=1;c[i+1]-=1;c[i+2]-=1
   if f(c):return 1
   c[i]+=1;c[i+1]+=1;c[i+2]+=1
n='123456789'
for e in sys.stdin:
 c=[list(e).count(j)for j in n]
 a=[]
 for i in range(9):
  t=c[:];t[i]+=1
  if f(t):a+=[i+1]
 if a:print(*a)
 else:print(0)

Buggy python submission (verdict: Runtime Error):
import sys
def f(c,h=0):
 if 2 in c and sum(c)==2:return 1
 if 5 in c:return 0  # sum(c)==2
 if 4 in c:
     k=c.index(4);c[k]-=3
     if f(c,h+1):return 1
     c[k]+=3
 if 3 in c:
     k=c.index(3);c[k]-=3
     if f(c,h+1):return 1
     c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
      c[i]-=1;c[i+1]-=1;c[i+2]-=1
      if f(c,h+1):return 1
      c[i]+=1;c[i+1]+=1;c[i+2]+=1
n='123456789'
for e in sys.stdin:
 e=list(e.strip())
 a=[i for i in n if f([(e+[i]).count(j)for j in n])]
 print(*a if a else 0)


Fixed submission:
import sys
def f(c):
 if sum(c)in c:return 1
 if 5 in c:return 0
 if 4 in c:
  k=c.index(4);c[k]-=3
  if f(c):return 1
  c[k]+=3
 if 3 in c:
  k=c.index(3);c[k]-=3
  if f(c):return 1
  c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
   c[i]-=1;c[i+1]-=1;c[i+2]-=1
   if f(c):return 1
   c[i]+=1;c[i+1]+=1;c[i+2]+=1
n='123456789'
for e in sys.stdin:
 c=[list(e).count(j)for j in n]
 a=[]
 for i in range(9):
  t=c[:];t[i]+=1
  if f(t):a+=[i+1]
 if a:print(*a)
 else:print(0)
Buggy python submission (verdict: Runtime Error):
a,p='apple','peach'
t={a:p,p:a}
print(*[t[w]if 5==len(w)and if w in t else t[w[:5]]+w[5:]if w[:5]in t else w for w in input().split()])


Fixed submission:
a,p,t='apple','peach','_'
print(input().replace(a,t).replace(p,a).replace(t,p))
Buggy python submission (verdict: Runtime Error):
for _ in[0]*int(input()):
 M=''.join(sorted(input()))[::-1]
 print(int(M)-int(M[::-1].replace('0','')))


Fixed submission:
for _ in[0]*int(input()):
 M=''.join(sorted(input()))
 print(int(M[::-1])-int(M))

Buggy python submission (verdict: Runtime Error):
for _ in[0]*int(input()):
 M=''.join(sorted(input()))
 print(int(M[::-1])-int(M.replace('0','')))


Fixed submission:
for _ in[0]*int(input()):
 M=''.join(sorted(input()))
 print(int(M[::-1])-int(M))
Buggy python submission (verdict: Runtime Error):
for e in iter(input,'0'):
 e=int(e)
 print(sum(n//5**i)for i in range(1,6)))


Fixed submission:
for e in iter(input,'0'):print(sum(int(e)//5**i for i in range(1,7)))

Buggy python submission (verdict: Runtime Error):
for e in iter(input,'0'):
 e=int(e)
 print(sum(e//5**i)for i in range(1,6)))


Fixed submission:
for e in iter(input,'0'):print(sum(int(e)//5**i for i in range(1,7)))

Buggy python submission (verdict: Runtime Error):
for e in iter(input,'0'):
 e=int(e)
 print(sum(e//5**ifor i in range(1,6)))


Fixed submission:
for e in iter(input,'0'):print(sum(int(e)//5**i for i in range(1,7)))
Buggy python submission (verdict: Runtime Error):
import sys
for e in sys.stdin:
 a,b,n=map(int,e.split())
 print(sum(int(i)for i in str(a/b)[2:][:n]))


Fixed submission:
import sys
for e in sys.stdin:
 a,b,n=map(int,e.split())
 print(sum(a*10**i//b%10 for i in range(1,n+1)))
Buggy python submission (verdict: Runtime Error):
import sys
for e in sys.stdin:
 t=[a,
 a*2,
 a*2/3,
 a*2/3*2,
 a*2/3*2/3,
 a*2/3*2/3*2,
 a*2/3*2/3*2/3,
 a*2/3*2/3*2/3*2,
 a*2/3*2/3*2/3*2/3,
 a*2/3*2/3*2/3*2/3*2]
 print(sum(t))


Fixed submission:
import sys
for e in sys.stdin:print(float(e)*211/27)
Buggy python submission (verdict: Runtime Error):
import sys
for x in sys.stdin:
 a,b,c=list(map(int,x.split()))
 print(['YES','NO'][len(set(range(1,21-sum(a,b)))-{a,b,c})/7<.5])


Fixed submission:
import sys
for x in sys.stdin:
 a,b,c=map(int,x.split())
 print(['YES','NO'][len({*range(1,21-a-b)}-{a,b,c})<3.5])
Buggy python submission (verdict: Runtime Error):
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print({*c}.sort()[::-1].index(d[int(y)])+1)


Fixed submission:
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print(sorted({*c})[::-1].index(d[int(y)])+1)

Buggy python submission (verdict: Runtime Error):
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print({*c}.sort()[::-1].index(d[int(y)])+1)


Fixed submission:
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print(sorted({*c})[::-1].index(d[int(y)])+1)
Buggy python submission (verdict: Runtime Error):
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c=int(e.split(',')[0])
  if c in a[b]:a[b][c]+=1
  else:a[b][c]=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])


Fixed submission:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c,_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])

Buggy python submission (verdict: Runtime Error):
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c=int(e.split(',')[0]);a[b][c]=1+[0,a[b][c]][c in a[b]]
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])


Fixed submission:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c,_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])

Buggy python submission (verdict: Runtime Error):
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])


Fixed submission:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c,_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])
Buggy python submission (verdict: Runtime Error):
def e(x,y):
 A[y][x]='0'
 for dx,dy in[(i,0),(0,i)for i in range(-3,4)]:
  if 0<=x+dx<8 and 0<=y+dy<8 and A[y+dy][x+dx]=='1':e(x+dx,y+dy)

for i in range(int(input())):
 print(f'Data {i+1}:')
 input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(*r,sep='')


Fixed submission:
def b(x,y):
 A[y][x]='0'
 for d in range(-3,4):
  0<=x+d<8and'1'==A[y][x+d]and b(x+d,y)
  0<=y+d<8and'1'==A[y+d][x]and b(x,y+d)
e=input
for i in range(int(e())):
 print(f'Data {i+1}:')
 e()
 A=[list(e())for _ in[0]*8]
 b(int(e())-1,int(e())-1)
 for r in A:print(*r,sep='')

Buggy python submission (verdict: Runtime Error):
def e(x,y):
 A[y][x]='0'
 for dx,dy in[(i,0),(0,i)for i in range(-3,4)if i]:
  if 0<=x+dx<8 and 0<=y+dy<8 and A[y+dy][x+dx]=='1':e(x+dx,y+dy)

for i in range(int(input())):
 print(f'Data {i+1}:')
 input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(*r,sep='')


Fixed submission:
def b(x,y):
 A[y][x]='0'
 for d in range(-3,4):
  0<=x+d<8and'1'==A[y][x+d]and b(x+d,y)
  0<=y+d<8and'1'==A[y+d][x]and b(x,y+d)
e=input
for i in range(int(e())):
 print(f'Data {i+1}:')
 e()
 A=[list(e())for _ in[0]*8]
 b(int(e())-1,int(e())-1)
 for r in A:print(*r,sep='')

Buggy python submission (verdict: Runtime Error):
def e(x,y):
 A[y][x]='0'
 for t in range(-3,4):
  if 0<=x+dx<8 and A[y][x+dx]=='1':e(x+dx,y)
  if 0<=y+dy<8 and A[y+dy][x]=='1':e(x,y+dy)

for i in range(int(input())):
 print(f'Data {i+1}:')
 input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(*r,sep='')


Fixed submission:
def b(x,y):
 A[y][x]='0'
 for d in range(-3,4):
  0<=x+d<8and'1'==A[y][x+d]and b(x+d,y)
  0<=y+d<8and'1'==A[y+d][x]and b(x,y+d)
e=input
for i in range(int(e())):
 print(f'Data {i+1}:')
 e()
 A=[list(e())for _ in[0]*8]
 b(int(e())-1,int(e())-1)
 for r in A:print(*r,sep='')
Buggy python submission (verdict: Runtime Error):
while 1:
 x,h=int(input()),int(input())
 if x:print(x*x+((x/2)**2+h**2)**.5*x*2)


Fixed submission:
for x in iter(input,'0'):x=int(x);print(x*x+2*x*((x/2)**2+int(input())**2)**.5)
Buggy python submission (verdict: Runtime Error):
p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
for e in iter(input,'-1'):
 h,m,s=map(int,e.split())
 d=7200-h*3600-m*60-s
 p(d);p(d*3)


Fixed submission:
p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
for e in iter(input,'-1 -1 -1'):
 h,m,s=map(int,e.split())
 d=7200-h*3600-m*60-s
 p(d);p(d*3)

Buggy python submission (verdict: Runtime Error):
p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
for e in iter(input,'-1\n'):
 h,m,s=map(int,e.split())
 d=7200-h*3600-m*60-s
 p(d);p(d*3)


Fixed submission:
p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
for e in iter(input,'-1 -1 -1'):
 h,m,s=map(int,e.split())
 d=7200-h*3600-m*60-s
 p(d);p(d*3)
Buggy python submission (verdict: Runtime Error):
for e in iter(input,'-1'):
 s,w,h=e.split(',')
 float(w)/float(h)**2<25 or print(s)


Fixed submission:
import sys
for e in sys.stdin:
 s,w,h=e.split(',')
 float(w)/float(h)**2<25 or print(s)

Buggy python submission (verdict: Runtime Error):
for e in iter(input,'-1 -1'):
 s,w,h=e.split(',')
 float(w)/float(h)**2<25 or print(s)


Fixed submission:
import sys
for e in sys.stdin:
 s,w,h=e.split(',')
 float(w)/float(h)**2<25 or print(s)
Buggy python submission (verdict: Runtime Error):
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
x,y=p[0]
print(abs(sum((p[i][0]-x)*(p[i+1][1]-y)-(p[i][1]-y)*(p[i+1][0]-x))for i in range(1,len(p)-1)))/2)


Fixed submission:
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
n=len(p)
for i in range(n):a,b=p[i];c,d=p[-~i%n];s+=a*d-b*c
print(abs(s)/2)

Buggy python submission (verdict: Runtime Error):
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
n=len(p)
for i in range(n):a,b=p[i];c,d=p[-~i%n];s+=a*d-b*c
print(s/2)

/////////////


Fixed submission:
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
n=len(p)
for i in range(n):a,b=p[i];c,d=p[-~i%n];s+=a*d-b*c
print(abs(s)/2)

Buggy python submission (verdict: Runtime Error):
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
n=len(p)
for i in range(n):a,b=p[i];c,d=p[-~i%n];s+=a*d-b*c
print(s/2)

//      abs abs


Fixed submission:
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
n=len(p)
for i in range(n):a,b=p[i];c,d=p[-~i%n];s+=a*d-b*c
print(abs(s)/2)
Buggy python submission (verdict: Runtime Error):
import sys
from math import complex as C
for e in sys.stdin:
 a,b,c,d,e,f=map(float,e.split(','))
 z,w,q=C(a,b),C(c,d),C(e,f)
 w-=z
 z+=(w/abs(w))**2*(q-z).conjugate()
 print(z.real,z.imag)


Fixed submission:
import sys
from math import*
for e in sys.stdin:
 a,b,c,d,e,f=map(float,e.split(','))
 z,w,q=complex(a,b),complex(c,d),complex(e,f)
 w-=z
 z+=(w/abs(w))**2*(q-z).conjugate()
 print(z.real,z.imag)
Buggy python submission (verdict: Runtime Error):
import re
print(*[x for x in re.split(r'\s|"|,|\.',input())if 2<len(s)<7])


Fixed submission:
import re
print(*[x for x in re.split(r'\s|"|,|\.',input())if 2<len(x)<7])
Buggy python submission (verdict: Runtime Error):
import sys
v=[0]*101
for e in sys.stdin:
 a,b=map(int,e.split())
 v[a]+=1;v[b]+=1
 if a==0:
  print(['OK','NG'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)-2])
  v=[0]*101


Fixed submission:
import sys
v=[0]*100
for e in sys.stdin:
 a,b=map(int,e.split())
 v[a]+=1;v[b]+=1
 if a==0:
  print(['NG','OK'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)==2])
  v=[0]*100
Buggy python submission (verdict: Runtime Error):
def x(p0, p1):
    d = abs(p0 - p1)
    if d > 2:
        return []
    elif d == 2:
        return [(p0 + p1) / 2]
    else:
        m = (p0 + p1) / 2
        v = m - p0
        w = complex(v.imag, -v.real)
        l = abs(w)
        h = (1 - l ** 2) ** .5 * w / l
        return [m + h, m - h]

for e in iter(input, '0'):
    n = int(e)
    P = [complex(*map(float, input().split(','))) for _ in [0] * n]
    Q = []
    for i in range(n):
        for j in range(i + 1, n):
            Q += x(P[i], P[j])
    print(max(1, *[sum(1.01 >= abs(q - p) for p in P) for q in Q]))


Fixed submission:
def x(p0, p1):
    d = abs(p0 - p1)
    if d > 2:
        return []
    elif d == 2:
        return [(p0 + p1) / 2]
    else:
        m = (p0 + p1) / 2
        v = m - p0
        w = complex(v.imag, -v.real)
        l = abs(w)
        h = (1 - l ** 2) ** .5 * w / l
        return [m + h, m - h]

for e in iter(input, '0'):
    n = int(e)
    P = [complex(*map(float, input().split(','))) for _ in [0] * n]
    Q = []
    for i in range(n):
        for j in range(i + 1, n):
            Q += x(P[i], P[j])
    print(max([sum(1.01 >= abs(q - p) for p in P) for q in Q] + [1]))
Buggy python submission (verdict: Runtime Error):
b=0
for e in iter(input,'0 0'):
 if b:print()
 b=u=1
 s,t=map(int,e.split())
 for y in range(s,t+1)if y%4==0 and y%100!=0 or y%400==0:print(y);u=0
 if u:print('NA')


Fixed submission:
p=print
b=1
for e in iter(input,'0 0'):
 b or p()
 b=f=0;s,t=map(int,e.split())
 for y in range(s,t+1):
  if(y%4==0)*(y%100)or y%400==0:p(y);f=1
 f or p('NA')

Buggy python submission (verdict: Runtime Error):
p=print
b=0
for e in iter(input,'0 0'):
 if b:p()
 b=f=1;s,t=map(int,e.split())
 for y in range(s,t+1):
  if(y%4==0)*(y%100)or y%400==0:p(y);f=0
 if u:p('NA')


Fixed submission:
p=print
b=1
for e in iter(input,'0 0'):
 b or p()
 b=f=0;s,t=map(int,e.split())
 for y in range(s,t+1):
  if(y%4==0)*(y%100)or y%400==0:p(y);f=1
 f or p('NA')
Buggy python submission (verdict: Runtime Error):
d={}
for _ in[0]*int(input()):
 a,v=map(int,input().split())
 d[a]=v
m=max(d.items(),key=lambda x:x[1])
print(min(d[m]),m)


Fixed submission:
d={}
for _ in[0]*int(input()):
 a,v=map(int,input().split())
 d[v]=d[v]if v in d and a>d[v]else a
m=max(d)
print(d[m],m)

Buggy python submission (verdict: Runtime Error):
d={}
for _ in[0]*int(input()):
 a,v=map(int,input().split())
 d[a]=v
m=max(d.items(),key=lambda x:x[1])[0]
print(m,min(d[m]))


Fixed submission:
d={}
for _ in[0]*int(input()):
 a,v=map(int,input().split())
 d[v]=d[v]if v in d and a>d[v]else a
m=max(d)
print(d[m],m)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=[0]*-~n
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 m=max(s)
 print(s.index(m),m)


Fixed submission:
import sys
def f():
 w=m=0;n,q=map(int,input().split());s=[0]*-~n
 for e in sys.stdin:
  a,v=map(int,e.split());s[a]+=v
  if v<0 and a==w:m=max(s);w=s.index(m)
  elif s[a]>m:w,m=a,s[a]
  elif s[a]==m and w>a:w=a
  print(w,m)
f()

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 if v<0 and a==w:m=max(s),w=s.index(m)
 elif s[a]>maxv:w,m=a,s[a]
 elif s[a]==maxv:w=min(w,a)
 print(w,m)


Fixed submission:
import sys
def f():
 w=m=0;n,q=map(int,input().split());s=[0]*-~n
 for e in sys.stdin:
  a,v=map(int,e.split());s[a]+=v
  if v<0 and a==w:m=max(s);w=s.index(m)
  elif s[a]>m:w,m=a,s[a]
  elif s[a]==m and w>a:w=a
  print(w,m)
f()

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 if v<0 and a==w:m=max(s);w=s.index(m)
 elif s[a]>maxv:w,m=a,s[a]
 elif s[a]==maxv:w=min(w,a)
 print(w,m)


Fixed submission:
import sys
def f():
 w=m=0;n,q=map(int,input().split());s=[0]*-~n
 for e in sys.stdin:
  a,v=map(int,e.split());s[a]+=v
  if v<0 and a==w:m=max(s);w=s.index(m)
  elif s[a]>m:w,m=a,s[a]
  elif s[a]==m and w>a:w=a
  print(w,m)
f()
Buggy python submission (verdict: Runtime Error):
while 1:
 n=int(input())
 if n:
  a=[list(map(int,input().split()))for _ in[0]*n]
  for r in a:
   for s in r:print(f"{s:5}",end='')
   print(f"{sum(r):5}")
  for c in zip(*a):print(f"{sum(c):5}",end='')
  print(f"{sum([sum(r)for r in a]):5}")


Fixed submission:
while 1:
 n=int(input())
 if n==0:break;
 a=[]
 for i in range(n):
  b=list(map(int,input().split()))
  a+=[b+[sum(b)]]
  for s in a[i]:print("%5d"%s,end='')
  print()
 for c in zip(*a):print("%5d"%sum(c),end='')
 print()

Buggy python submission (verdict: Runtime Error):
while 1:
 n=int(input())
 if n==0:break;
 a=[]
 for i in range(n):
  a[i]=[list(map(int,input().split()))]
  a[i]+=[sum(a[i])]
  for s in a[i]:print("%5d"%s,end='')
  print()
 for c in zip(*a):print("%5d"%sum(c),end='')
 print()


Fixed submission:
while 1:
 n=int(input())
 if n==0:break;
 a=[]
 for i in range(n):
  b=list(map(int,input().split()))
  a+=[b+[sum(b)]]
  for s in a[i]:print("%5d"%s,end='')
  print()
 for c in zip(*a):print("%5d"%sum(c),end='')
 print()
Buggy python submission (verdict: Runtime Error):
for _ in[0]*int(input()):
 r=o=s=0
 while 1:
  a=input()[1]
  if'I'==a:
   if r<3:r+=1
   else:s+=1
  elif'O'==a:s+=r+1;r=0
  else:
   if r<3:o+=1
   else:print(s);break


Fixed submission:
n=int(input())
r=o=s=0
while n:
 a=input()[1]
 if'I'==a:
  if r<3:r+=1
  else:s+=1
 elif'O'==a:s+=r+1;r=0
 else:
  if o<2:o+=1
  else:print(s);n-=1;r=o=s=0
Buggy python submission (verdict: Time Limit Exceeded):
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while'.'!=m[y][x]:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  else:s|={(x,y)}
 else:print('LOOP')


Fixed submission:
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  c=m[y][x]
  if'>'==c:x+=1;
  if'v'==c:y+=1;
  if'<'==c:x-=1;
  if'^'==c:y-=1;
  if'.'==c:print(x,y);break
  if(x,y)in s:print('LOOP');break
  else:s|={(x,y)}
Buggy python submission (verdict: Runtime Error):
import sys
for a in sys.stdin:
 if'0'==a:break
 s=list(map(int,input().split()))
 c=0
 while 1:
  t=s;s=[t.count(e)for e in t]
  if t==s:break
  c+=1
 print(c);print(*s)


Fixed submission:
while 1:
 a,b,_=sorted(map(int,input().split()))
 if a==0:break
 for _ in[0]*int(input()):print("OK"if(int(input())*2)**2>a*a+b*b else"NA")
Buggy python submission (verdict: Runtime Error):
while 1:
 n=int(input())
 if n:
  s=list(map(int,input().split()))
  c=0
  while 1:
   t=s;s=[t.count(e)for e in t]
   if t==s:break
   c+=1
  print(c);print(*s)


Fixed submission:
import sys
a=sys.stdin
while 1:
 if'0\n'==a.readline():break
 s=list(map(int,a.readline().split()))
 c=0
 while 1:
  t=s;s=[t.count(e)for e in t]
  if t==s:break
  c+=1
 print(c);print(*s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
a=sys.stdin
while 1:
 if'0'==a.readline():break
 s=list(map(int,a.readline().split()))
 c=0
 while 1:
  t=s;s=[t.count(e)for e in t]
  if t==s:break
  c+=1
 print(c);print(*s)


Fixed submission:
import sys
a=sys.stdin
while 1:
 if'0\n'==a.readline():break
 s=list(map(int,a.readline().split()))
 c=0
 while 1:
  t=s;s=[t.count(e)for e in t]
  if t==s:break
  c+=1
 print(c);print(*s)
Buggy python submission (verdict: Runtime Error):
R={"*":2,"/":2,"+":1,"-":1,"(":0,")":0}
for _ in[0]*int(input()):
 L=[];t=''
 for e in input()[:-1]:
  if e.isdigit():t+=e
  else:
   if t:L+=[t];t=''
   L+=e
 if t:L+=[t]
 P,S=[],[]
 for i in L:
  if"("==i:S+=i
  elif")"==i:
   while"("!=S[-1]:P+=S.pop()
   S.pop()
  elif i in R:
   while S and R[S[-1]]>=R[i]:P+=S.pop()
   S+=i
  else:P+=[i]
 while S:P+=S.pop()
 for x in P:
  S+=[str(eval(s.pop(-2)+p+s.pop()))if x in"+-*/"else x]
 print(*S)


Fixed submission:
R={"*":2,"/":2,"+":1,"-":1,"(":0,")":0}
for _ in[0]*int(input()):
 L=[];t=''
 for e in input()[:-1]:
  if e.isdigit():t+=e
  else:
   if t:L+=[t];t=''
   L+=e
 if t:L+=[t]
 P,S=[],[]
 for i in L:
  if"("==i:S+=i
  elif")"==i:
   while"("!=S[-1]:P+=S.pop()
   S.pop()
  elif i in R:
   while S and R[S[-1]]>=R[i]:P+=S.pop()
   S+=i
  else:P+=[i]
 while S:P+=S.pop()
 for x in P:
  S+=[str(int(eval(S.pop(-2)+x+S.pop())))if x in"+-*/"else x]
 print(*S)

Buggy python submission (verdict: Runtime Error):
R={"*":2,"/":2,"+":1,"-":1,"(":0,")":0}
for _ in[0]*int(input()):
 L=[];t=''
 for e in input()[:-1]:
  if e.isdigit():t+=e
  else:
   if t:L+=[t];t=''
   L+=e
 if t:L+=[t]
 P,S=[],[]
 for i in L:
  if"("==i:S+=i
  elif")"==i:
   while"("!=S[-1]:P+=S.pop()
   S.pop()
  elif i in R:
   while S and R[S[-1]]>=R[i]:P+=S.pop()
   S+=i
  else:P+=[i]
 while S:P+=S.pop()
 for x in P:
  S+=[str(eval(S.pop(-2)+p+S.pop()))if x in"+-*/"else x]
 print(*S)


Fixed submission:
R={"*":2,"/":2,"+":1,"-":1,"(":0,")":0}
for _ in[0]*int(input()):
 L=[];t=''
 for e in input()[:-1]:
  if e.isdigit():t+=e
  else:
   if t:L+=[t];t=''
   L+=e
 if t:L+=[t]
 P,S=[],[]
 for i in L:
  if"("==i:S+=i
  elif")"==i:
   while"("!=S[-1]:P+=S.pop()
   S.pop()
  elif i in R:
   while S and R[S[-1]]>=R[i]:P+=S.pop()
   S+=i
  else:P+=[i]
 while S:P+=S.pop()
 for x in P:
  S+=[str(int(eval(S.pop(-2)+x+S.pop())))if x in"+-*/"else x]
 print(*S)
Buggy python submission (verdict: Runtime Error):
while 1:
 a=b=0;n=int(input())
 if n:
  for i in[0]*n:
   s,t=map(int,input().split())
   if s>t:a+=s+t
   elif s<t:b+=s+t
   else:a+=s;b+=t
  print(a,b)


Fixed submission:
import sys
d=0
for e in sys.stdin:
 c=list(map(int,e.split()))
 if len(c)>1:
  s,t=c;d=1
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 else:
  if d:print(a,b)
  a=b=0

Buggy python submission (verdict: Runtime Error):
while 1:
 a=b=0;n=int(input())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,input().split())
  b+=s if s<t else a+=s
  a+=t if s>t else b+=t
 print(a,b)


Fixed submission:
import sys
d=0
for e in sys.stdin:
 c=list(map(int,e.split()))
 if len(c)>1:
  s,t=c;d=1
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 else:
  if d:print(a,b)
  a=b=0

Buggy python submission (verdict: Runtime Error):
import sys
e=iter(sys.stdin)
while 1:
 a=b=0;n=int(e)
 if n==0:break
 for i in[0]*n:
  s,t=map(int,e.split())
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 print(a,b)


Fixed submission:
import sys
d=0
for e in sys.stdin:
 c=list(map(int,e.split()))
 if len(c)>1:
  s,t=c;d=1
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 else:
  if d:print(a,b)
  a=b=0
Buggy python submission (verdict: Runtime Error):
import sys
s=sys.stdin
r=readline()
while 1:
 n=int(s.r)
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=s.r.strip().split()
  d[k]=v
 a=''
 for _ in[0]*int(s.readline()):
  e=s.r.strip()
  a+=d[e]if e in d else e
 print(a)


Fixed submission:
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):e=s();d[e[0]]=e[2]
 print(''.join(d.get(*[s()[0]]*2)for _ in[0]*int(s())))

Buggy python submission (verdict: Runtime Error):
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):
  k,v=s()[:-1].split()
  d[k]=v
 print(d.get(*[s()[0]]*2)for _ in[0]*int(s()),sep='')


Fixed submission:
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):e=s();d[e[0]]=e[2]
 print(''.join(d.get(*[s()[0]]*2)for _ in[0]*int(s())))