Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
"\n".join(reverse(sort([input() for i in range(10)]))[:3])

Fixed submission:
print "\n".join([str(x) for x in (sorted([input() for i in range(10)])[:-4:-1])])

Buggy python submission (verdict: Runtime Error):
"\n".join(reversed(sorted([input() for i in range(10)]))[:3])

Fixed submission:
print "\n".join([str(x) for x in (sorted([input() for i in range(10)])[:-4:-1])])

Buggy python submission (verdict: Runtime Error):
"\n".join(sort([input() for i in range(10)])[:-3:-1])

Fixed submission:
print "\n".join([str(x) for x in (sorted([input() for i in range(10)])[:-4:-1])])

Buggy python submission (verdict: Runtime Error):
"\n".join(sorted([input() for i in range(10)])[:-3:-1])

Fixed submission:
print "\n".join([str(x) for x in (sorted([input() for i in range(10)])[:-4:-1])])
Buggy python submission (verdict: Runtime Error):
import sys
print "\n".join([len(str(sum([int(x) for x in l.split(' ')]))) for l in open(sys.stdin)])

Fixed submission:
import sys
print "\n".join(str(len(str(sum(int(x) for x in l.split(' '))))) for l in sys.stdin)

Buggy python submission (verdict: Runtime Error):
import sys
print "\n".join([len(str(sum([int(x) for x in l.split(' ')]))) for l in sys.stdin])

Fixed submission:
import sys
print "\n".join(str(len(str(sum(int(x) for x in l.split(' '))))) for l in sys.stdin)
Buggy python submission (verdict: Runtime Error):
[print(s) for s in map(lambda x:x[0]+x[1]==x[2]　and 'YES' or 'NO', [sorted(int(x)**2 for x in input().split(' ') for i in range(int(input()))])]

Fixed submission:
print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))]))

Buggy python submission (verdict: Runtime Error):
[print(s) for s in map(lambda x:x[0]+x[1]==x[2]　and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ') for i in range(int(raw_input()))])]

Fixed submission:
print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))]))

Buggy python submission (verdict: Runtime Error):
[print(s) for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))])]

Fixed submission:
print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))]))

Buggy python submission (verdict: Runtime Error):
a=[print(s) for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))])]

Fixed submission:
print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))]))

Buggy python submission (verdict: Runtime Error):
a=[print(s) for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))])]

Fixed submission:
print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))]))

Buggy python submission (verdict: Runtime Error):
a=[print(s) for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO',[sorted(int(x)**2 for x in input().split(' ')) for i in range(int(input()))])]

Fixed submission:
print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))]))
Buggy python submission (verdict: Runtime Error):
def curserch(N,k,t,P,n):
    g = 0
    t = t+1
    P[k]["d"] = t
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            P[i]["f"] = g = curserch(N,i,t,P,n)
    if g !=0:
        return g+1
    else:
        return t+1

n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[{"d":0} for i in range(n+1)]
P[1]["f"] = curserch(A,1,0,P,n)
j=1
for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"]) 

Fixed submission:
T = [0]

def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0]


n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[{"d":0} for i in range(n+1)]
for i in range(1,n+1):
    if P[i]["d"]==0:
        curserch(A,i,T,P,n)
        T[0] = T[0]+1
        P[i]["f"]=T[0]
for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"])

Buggy python submission (verdict: Runtime Error):
def curserch(N,k,t,P,n):
    g = 0
    t = t+1
    P[k]["d"] = t
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            P[i]["f"] = g = curserch(N,i,t,P,n)
    if g !=0:
        return g+1
    else:
        return t+1

n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[{"d":0} for i in range(n+1)]
P[1]["f"] = curserch(A,1,0,P,n)
for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"]) 

Fixed submission:
T = [0]

def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0]


n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[{"d":0} for i in range(n+1)]
for i in range(1,n+1):
    if P[i]["d"]==0:
        curserch(A,i,T,P,n)
        T[0] = T[0]+1
        P[i]["f"]=T[0]
for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"])
Buggy python submission (verdict: Runtime Error):
a=[]
n=int(input())
s=input()
a=list(map(int,s.split()))
insertionSort(a,n)

def insertionSort(a,n):
    for i in range(n):
        print(a[i],end="")
        if(i!=n-1):
            print(" ",end="")
    print("")    
    for i in range(1,n):
        v=a[i]
        j=i-1
        while(j>=0 and a[j]>v):
            a[j+1] = a[j]
            j-=1
        a[j+1] = v
        for i in range(n):
            print(a[i],end="")
            if(i!=n-1):
                print(" ",end="")
        print("")

Fixed submission:
def insertionSort(a,n):
    for i in range(n):
        print(a[i],end="")
        if(i!=n-1):
            print(" ",end="")
    print("")    
    for i in range(1,n):
        v=a[i]
        j=i-1
        while(j>=0 and a[j]>v):
            a[j+1] = a[j]
            j-=1
        a[j+1] = v
        for i in range(n):
            print(a[i],end="")
            if(i!=n-1):
                print(" ",end="")
        print("")

a=[]
n=int(input())
s=input()
a=list(map(int,s.split()))
insertionSort(a,n)
Buggy python submission (verdict: Time Limit Exceeded):
a=[]
n=int(input())
while(n>0):
    b=int(input())
    a.append(b)
    n-=1

a.reverse()
sa=a[0]-a[1]
for i,e in enumerate(a):
    for j in a[i+1:]:
        sb=e-j
        if(sb>sa):
            sa=sb

print(sa)

Fixed submission:
a=[]
n=int(input())
i=0
while(n>i):
    b=int(input())
    a.append(b)
    i+=1
score=-1000000000
mini = a[0]
for i in a[1:]:
    if(i-mini>score):
        score = i-mini
    if(mini>i):
        mini=i
    

print(score)

Buggy python submission (verdict: Time Limit Exceeded):
a=[]
n=int(input())
nn=n
while(nn>0):
    b=int(input())
    a.append(b)
    nn-=1

a.reverse()
sa=a[0]-a[1]
for i in range(1,n):
    sb=a[i-1]-min(a[i:])
    if(sb>sa):
        sa=sb

print(sa)

Fixed submission:
a=[]
n=int(input())
i=0
while(n>i):
    b=int(input())
    a.append(b)
    i+=1
score=-1000000000
mini = a[0]
for i in a[1:]:
    if(i-mini>score):
        score = i-mini
    if(mini>i):
        mini=i
    

print(score)
Buggy python submission (verdict: Runtime Error):
dic = []
n = int(input())
for i in range(n):
    a = input()
    t=list(map(int,a.split()))
    if t[0] == "insert":
        dic.append(t[1])
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")

Fixed submission:
dic=dict()
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1]] = True
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")

Buggy python submission (verdict: Time Limit Exceeded):
dic = []
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic.append(t[1])
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")
    

Fixed submission:
dic=dict()
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1]] = True
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")

Buggy python submission (verdict: Time Limit Exceeded):
ind = {"A":0,"C":1,"G":2,"T":3}
dic = [[],[],[],[]]
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[ind[t[1][0]]].append(t[1])
    else:
        if t[1] in dic[ind[t[1][0]]]:
            print("yes")
        else:
            print("no")
    

Fixed submission:
dic=dict()
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1]] = True
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")

Buggy python submission (verdict: Time Limit Exceeded):
dic = {"A":[],"C":[],"G":[],"T":[]}
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1][0]].append(t[1])
    else:
        if t[1] in dic[t[1][0]]:
            print("yes")
        else:
            print("no")
    

Fixed submission:
dic=dict()
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1]] = True
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")

Buggy python submission (verdict: Time Limit Exceeded):
dic = []
ind = {"A":0,"C":1,"G":2,"T":3}
dic = [[[],[],[],[]] for i in range(12)]
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[len(t[1])-1][ind[t[1][0]]].append(t[1])
    else:
        if t[1] in dic[len(t[1])-1][ind[t[1][0]]]:
            print("yes")
        else:
            print("no")

Fixed submission:
dic=dict()
n = int(input())
for i in range(n):
    a = input()
    t=a.split()
    if t[0] == "insert":
        dic[t[1]] = True
    else:
        if t[1] in dic:
            print("yes")
        else:
            print("no")
Buggy python submission (verdict: Time Limit Exceeded):
def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

n=int(input())
A=list(map(int,str.split(input())))
q = int(input())
m=list(map(int,str.split(input())))

for mi in m:
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")

Fixed submission:
def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

    

n=int(input())
A=list(map(int,str.split(input())))
q = int(input())
m=list(map(int,str.split(input())))




mini = min(A)
nor = sum(A)

for mi in m:
    if mi < mini or mi > nor:
        print("no")
        continue
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")

Buggy python submission (verdict: Runtime Error):
def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

n=int(input())
A=list(map(int,str.split(input())))
q = int(input())
m=list(map(int,str.split(input())))

mini = min(A)
nor = sum(A)

for mi in m:
    if mi < mini or mi > nor:
        print(no)
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")

Fixed submission:
def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

    

n=int(input())
A=list(map(int,str.split(input())))
q = int(input())
m=list(map(int,str.split(input())))




mini = min(A)
nor = sum(A)

for mi in m:
    if mi < mini or mi > nor:
        print("no")
        continue
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")
Buggy python submission (verdict: Runtime Error):
def partition(a,p,r):
    x=int(a[r][1:])
    i=p-1
    for j in range(p,r):
        if(int(a[j][1:])<=x):
            i+=1
            a[i],a[j]=a[j],a[i]
    a[i+1],a[r]=a[r],a[i+1]
    return i+1

def quicksort(a,p,r):
    if(p<r):
        q=partition(a,p,r)
        quicksort(a,p,q-1)
        quicksort(a,q+1,r)

a=[]
n=int(input())
for i in range(n):
    s=input()
    a.append("".join(s.split()))

b=list(a)
strr_bubble_sort(b,n)
c=list(a)
quicksort(c,0,n-1)

d=dict()
i=0
x="-1"
for i in c:
    if(x!=i[1:]):
        d[i[1:]]=[i[:1]]
        x=i[1:]
    else:
        d[x].append(i[:1])
    print(d)

message="Stable"

for i in reversed(a):
    if(i[1:] in d):
        print(d)
        if(d[i[1:]].pop()!=i[:1]):
            message="Not stable"
            break

print(message)

for i in c:
    print("%s %s"%(i[:1],i[1:]))

Fixed submission:
def partition(a,p,r):
    x=int(a[r][1:])
    i=p-1
    for j in range(p,r):
        if(int(a[j][1:])<=x):
            i+=1
            a[i],a[j]=a[j],a[i]
    a[i+1],a[r]=a[r],a[i+1]
    return i+1

def quicksort(a,p,r):
    if(p<r):
        q=partition(a,p,r)
        quicksort(a,p,q-1)
        quicksort(a,q+1,r)

a=[]
n=int(input())
for i in range(n):
    s=input()
    a.append("".join(s.split()))

c=list(a)
quicksort(c,0,n-1)

d=dict()
i=0
x="-1"
for i in c:
    if(x!=i[1:]):
        d[i[1:]]=[i[:1]]
        x=i[1:]
    else:
        d[x].append(i[:1])

message="Stable"

for i in reversed(a):
    if(i[1:] in d):
        if(d[i[1:]].pop()!=i[:1]):
            message="Not stable"
            break

print(message)

for i in c:
    print("%s %s"%(i[:1],i[1:]))
Buggy python submission (verdict: Runtime Error):
import math

a=int(input())

L = 2*math.pi*a
s = a*a*math.pi

print("%.6f"%(L),"%.6f"%(s))

Fixed submission:
(a,b)=[int(i) for i in input().split()]

print(int(a/b),int(a%b),"%.8f"%(a/b))
Buggy python submission (verdict: Runtime Error):
import math

a=int(input())

L = 2*math.pi*a
s = a*a*math.pi

print(???%.6f???%(L),???%.6f???%(s))

Fixed submission:
import math

n = float( input() )

L = 2*math.pi*n
S = n * n * math.pi

print("%.6f"%(S),"%.6f"%(L))

Buggy python submission (verdict: Runtime Error):
import math

a=int(input())

L = 2*math.pi*a
s = a*a*math.pi

print("%.6f"%(L),"%.6f"%(s))

Fixed submission:
import math

n = float( input() )

L = 2*math.pi*n
S = n * n * math.pi

print("%.6f"%(S),"%.6f"%(L))
Buggy python submission (verdict: Runtime Error):
n = int(input())
for i in range(n):
    (H,W)=[int(s) for s in input().split()]
    for j in range(H):
        print("#"*W)

Fixed submission:
while(True):
    (H,W)=[int(s) for s in input().split()]
    if (H,W) == (0,0):
        break
    for j in range(H):
        print("#"*W)
    print("")
Buggy python submission (verdict: Runtime Error):
import math
x = 0
y = 0
r = 90
while True:
    d,t=map(int, input().split())
    if d==0 and t==0:
        print(int(x),int(y),sep='\n')
        exit()
    x += math.cos(math.radians(r)) * d
    y += math.sin(math.radians(r)) * d
    r -= t

Fixed submission:
import math
x = 0
y = 0
r = 90
while True:
    d,t=map(int, input().split(','))
    if d==0 and t==0:
        print(int(x),int(y),sep='\n')
        exit()
    x += math.cos(math.radians(r)) * d
    y += math.sin(math.radians(r)) * d
    r -= t
Buggy python submission (verdict: Runtime Error):
import collections
import sys
cntr = collections.Counter
for line in sys.stdin:
    cntr[int(line)] += 1
lst = []
for k,v in cntr.items():
    lst.append((v,k))
lst.sort()
t = len(lst)-1
while t>0 and lst[t][0] == lst[t-1][0]:
    t -= 1
for i in range(t,len(lst)):
    print(lst[i][1])

Fixed submission:
import collections
import sys
cntr = collections.Counter()
for line in sys.stdin:
    cntr[int(line)] += 1
lst = []
for k,v in cntr.items():
    lst.append((v,k))
lst.sort()
t = len(lst)-1
while t>0 and lst[t][0] == lst[t-1][0]:
    t -= 1
for i in range(t,len(lst)):
    print(lst[i][1])
Buggy python submission (verdict: Runtime Error):
def solve():
	while 1:
		n = int(input())
		if n==0:
			break
		score_a=0
		score_b=0
		while n>0:
			(a,b)=map(int, input().split())
			if a>b:
				score_a = score_a + a + b
			elif a<b:
				score_b = score_b + a + b
			else:
				score_a = score_a + a
				score_b = score_b + b
			n = n-1
		print(score_a, score_b)

if __name__ == '__main__':
	solve()

Fixed submission:
def solve():
	import sys
	while 1:
		n = int(raw_input())
		if n==0:
			break
		score_a=0
		score_b=0
		while n>0:
			(a,b)=map(int, raw_input().split())
			if a>b:
				score_a = score_a + a + b
			elif a<b:
				score_b = score_b + a + b
			else:
				score_a = score_a + a
				score_b = score_b + b
			n = n-1
		print score_a, score_b

if __name__ == '__main__':
	solve()
Buggy python submission (verdict: Runtime Error):
while True:
    (n, r) = [int(x) for x in input().split()]
    if n==0 and r==0:
        exit()
    cards = [n-i for i in range(n)]
    for _ in range(r):
        (p, c) = [int(x) for x in input().split()]
        cards = cards[p-1:c] + cards[p-1:p-1+c] + cards[p-1+c:]
    print(cards[0])

Fixed submission:
while True:
    (n, r) = [int(x) for x in input().split()]
    if n==0 and r==0:
        exit()
    cards = [n-i for i in range(n)]
    for _ in range(r):
        (p, c) = [int(x) for x in input().split()]
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
    print(cards[0])
Buggy python submission (verdict: Runtime Error):
while True:
    n = int(input())
    if n == 0:
        exit()
    score = []
    for i in range(n):
        score.append(int(input()))
    print((sorted(score)[1:-1])//(n-2))

Fixed submission:
while True:
    n = int(input())
    if n == 0:
        exit()
    score = []
    for i in range(n):
        score.append(int(input()))
    print(sum(sorted(score)[1:-1])//(n-2))
Buggy python submission (verdict: Runtime Error):
def dfs(tiles, W, H, x, y):
    tiles[y][x] = '0'
    for dx,dy in ((-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)):
        if 0<=x+dx<W and 0<=y+dy<H and tiles[y+dy][x+dx]=='1':
            dfs(tiles, W, H, x+dx, y+dy)
    return

def main():
    while True:
        W,H = [int(x) for x in input().split()]
        if W==0 and H==0:
            exit()
        tiles = [[c for c in input().split()] for h in range(H)]
        cnt = 0
        for h in range(H):
            for w in range(W):
                if tiles[h][w] == '1':
                    cnt += 1
                    dfs(tiles, W, H, w, h)
        print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
def dfs(tiles, W, H, x, y):
    tiles[y][x] = '0'
    for dx,dy in ((-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)):
        if 0<=x+dx<W and 0<=y+dy<H and tiles[y+dy][x+dx]=='1':
            dfs(tiles, W, H, x+dx, y+dy)
    return

def main():
    while True:
        W,H = [int(x) for x in input().split()]
        if W==0 and H==0:
            exit()
        tiles = [input().split() for h in range(H)]
        cnt = 0
        for h in range(H):
            for w in range(W):
                if tiles[h][w] == '1':
                    cnt += 1
                    dfs(tiles, W, H, w, h)
        print(cnt)

if __name__ == '__main__':
    sys.setrecursionlimit(10000)
    main()

Buggy python submission (verdict: Runtime Error):
import sys
def dfs(tiles, W, H, x, y):
    tiles[y][x] = '0'
    for dx,dy in ((-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)):
        if 0<=x+dx<W and 0<=y+dy<H and tiles[y+dy][x+dx]=='1':
            dfs(tiles, W, H, x+dx, y+dy)
    return

def main():
    while True:
        W,H = [int(x) for x in input().split()]
        if W==0 and H==0:
            exit()
        tiles = [[c for c in input().split()] for h in range(H)]
        cnt = 0
        for h in range(H):
            for w in range(W):
                if tiles[h][w] == '1':
                    cnt += 1
                    dfs(tiles, W, H, w, h)
        print(cnt)

if __name__ == '__main__':
    sys.getrecursionlimit(10000)
    main()

Fixed submission:
import sys
def dfs(tiles, W, H, x, y):
    tiles[y][x] = '0'
    for dx,dy in ((-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)):
        if 0<=x+dx<W and 0<=y+dy<H and tiles[y+dy][x+dx]=='1':
            dfs(tiles, W, H, x+dx, y+dy)
    return

def main():
    while True:
        W,H = [int(x) for x in input().split()]
        if W==0 and H==0:
            exit()
        tiles = [input().split() for h in range(H)]
        cnt = 0
        for h in range(H):
            for w in range(W):
                if tiles[h][w] == '1':
                    cnt += 1
                    dfs(tiles, W, H, w, h)
        print(cnt)

if __name__ == '__main__':
    sys.setrecursionlimit(10000)
    main()
Buggy python submission (verdict: Runtime Error):
while True:
    flg = True
    S = input()
    if S = '.':
        exit()
    cnt = [0, 0]
    for c in S:
        if c == '[':
            cnt[0] += 1
        elif c == ']':
            cnt[0] -= 1
            if cnt[0] < 0:
                flg = False
                break
        elif c == '(':
            cnt[1] += 1
        elif c == ')':
            cnt[1] -= 1
            if cnt[1] < 0:
                flg = False
                break
        else:
            pass
    if cnt[0]>0 or cnt[1]>0:
        flg = False
    if flg:
        print('yes')
    else:
        print('no')

Fixed submission:
while True:
    flg = True
    S = input()
    if S == '.':
        exit()
    brackets = []
    for c in S:
        if c == '[':
            brackets.append('[')
        elif c == ']':
            if len(brackets) == 0:
                flg = False
                break
            if brackets.pop() != '[':
                flg = False
                break
        elif c == '(':
            brackets.append('(')
        elif c == ')':
            if len(brackets) == 0:
                flg = False
                break
            if brackets.pop() != '(':
                flg = False
                break
        else:
            pass
    if len(brackets) > 0:
        flg = False
    if flg:
        print('yes')
    else:
        print('no')