Buggy python submission (verdict: Runtime Error):
def solve(c,h,w,count):
	if 0 <= h < H and 0 <= w < W:
		if c in "#@*" and c == A[h][w]:
			A[h][w] = count
			solve(c,h+1,w,count)
			solve(c,h-1,w,count)
			solve(c,h,w+1,count)
			solve(c,h,w-1,count)
while 1:
	H,W = map(int,raw_input().split())
	if H == W == 0:
		break
	A = [list(raw_input()) for i in range(H)]
	count = 0
	for h in range(H):
		for w in range(W):
			if str(A[h][w]) in "#@*":
				solve(A[h][w],h ,w,count)
				count += 1
	print count

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def solve(c,h,w,count):
	if 0 <= h < H and 0 <= w < W:
		if c in "#@*" and c == A[h][w]:
			A[h][w] = count
			solve(c,h+1,w,count)
			solve(c,h-1,w,count)
			solve(c,h,w+1,count)
			solve(c,h,w-1,count)

while 1:
	H,W = map(int,raw_input().split())
	if H == W == 0:
		break
	A = [list(raw_input()) for i in range(H)]
	count = 0
	for h in range(H):
		for w in range(W):
			if str(A[h][w]) in "#@*":
				solve(A[h][w],h ,w,count)
				count += 1
	print count

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def solve(c,h,w,count):
	if 0 <= h < H and 0 <= w < W:
		if type(c) is not int and c == A[h][w]:
			A[h][w] = count
			solve(c,h+1,w,count)
			solve(c,h-1,w,count)
			solve(c,h,w+1,count)
			solve(c,h,w-1,count)

while 1:
	H,W = map(int,raw_input().split())
	if H == W == 0:
		break
	A = [list(raw_input()) for i in range(H)]
	count = 0
	for h in range(H):
		for w in range(W):
			if type(A[h][w]) is not int:
				solve(A[h][w],h ,w,count)
				count += 1
	print count

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def solve(c,h,w,count):
	if 0 <= h < H and 0 <= w < W:
		if type(A[h][w]) is not int and c == A[h][w]:
			A[h][w] = count
			for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]:
				solve(c,h+dh,w+dw,count)
while 1:
	H,W = map(int,raw_input().split())
	if H == W == 0:break
	A = [list(raw_input()) for i in range(H)]
	count = 0
	for h in range(H):
		for w in range(W):
			if type(A[h][w]) is not int:
				solve(A[h][w],h ,w,count)
				count += 1
	print count

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def solve(c,h,w):
	if A[h][w] == c:
		A[h][w] = "X"
		for dx,dy in zip((1,-1,0,0),(0,0,1,-1)):
			if 0 <= h+dh < H and 0 <= w+dw < W:
				solve(c,h+dh,w+dw)

while 1:
	H,W = map(int,raw_input().split())
	if H == W == 0: break
	count = 0
	for h in range(H):
		for w in range(W):
			if A[h][w] != "X":
				solve(A[h][w],h,w)
				count += 1
	print count

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def solve(s,i,x,y):
	A[y][x] = i
	if x < W-1 and A[y][x+1] == s: solve(s,i,x+1,y)
	if y < H-1 and A[y+1][x] == s: solve(s,i,x,y+1)
	if x > 0   and A[y][x-1] == s: solve(s,i,x-1,y)
	if y > 0   and A[y-1][x] == s: solve(s,i,x,y-1)
	
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	i = 1
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				solve(A[y][x],i,x,y)
				i += 1
	print max([max(A[i]) for i in range(H)])

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	A[y][x] = 0
	if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	i = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				i += 1
	print i

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	A[y][x] = 0
	if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)

while 1:
	H,W = map(int,raw_input().split())
	if H == 0 and W == 0: break
	A = [list(raw_input()) for i in range(H)]
	i = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				i += 1
	print i

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(A,s,x,y):
	A[y][x] = 0
	if x < W-1 and A[y][x+1] == s: fill0(A,s,x+1,y)
	if y < H-1 and A[y+1][x] == s: fill0(A,s,x,y+1)
	if x > 0   and A[y][x-1] == s: fill0(A,s,x-1,y)
	if y > 0   and A[y-1][x] == s: fill0(A,s,x,y-1)

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A,A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill0(s,x+1,y); fill0(s,x,y+1); fill0(s,x-1,y); fill0(s,x,y-1)

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill0(s,x+1,y); fill0(s,x,y+1); fill0(s,x-1,y); fill0(s,x,y-1)
	return
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill0(s,x+1,y); fill0(s,x,y+1); fill0(s,x-1,y); fill0(s,x,y-1)
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill0(s,x+1,y); fill0(s,x,y+1); fill0(s,x-1,y); fill0(s,x,y-1)
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	print 1

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill0(s,x+1,y); fill0(s,x,y+1); fill0(s,x-1,y); fill0(s,x,y-1)
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill0(s,x+1,y); fill0(s,x,y+1); fill0(s,x-1,y); fill0(s,x,y-1)
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print 0

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(A,H,W,s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill0(A,H,W,s,x+1,y); fill0(A,H,W,s,x,y+1); fill0(A,H,W,s,x-1,y); fill0(A,H,W,s,x,y-1)
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(H,W,A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill(s,x+1,y); fill(s,x,y+1); fill(s,x-1,y); fill(s,x,y-1)
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] != 0:
				fill(A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill(s,x,y):
	if 0 <= x <= W-1 and 0 <= y <= H-1 and A[y][x] == s:
		A[y][x] = 0
		fill(s,x+1,y); fill(s,x,y+1); fill(s,x-1,y); fill(s,x,y-1)
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for b in range(H):
		for a in range(W):
			if A[b][a] != 0:
				fill(A[b][a],a,b)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
     A[y][x] = 0
     if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
     if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
     if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
     if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)

while 1:
     H,W = map(int,raw_input().split())
     if H == 0: break
     A = [list(raw_input()) for i in range(H)]
     ans = 0
     for y in range(H):
          for x in range(W):
               if A[y][x] in ["#","@","*"]:
					try:
	                    fill0(A[y][x],x,y)
	                    ans += 1
                    except:
                    	pass
     print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	try: A[y][x] = 0
	except: pass
	if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	A[y][x] = 0
	if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for yi in range(H):
		for xi in range(W):
			if A[yi][xi] in ["#","@","*"]:
				fill0(A[yi][xi],xi,yi)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	A[y][x] = 0
	try: if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	except: pass
	try: if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	except: pass
	try: if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	except: pass
	try: if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)
	except: pass

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	try: A[y][x] = 0
	except: pass
	try: if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	except: pass
	try: if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	except: pass
	try: if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	except: pass
	try: if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)
	except: pass

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count

Buggy python submission (verdict: Runtime Error):
def fill0(s,x,y):
	global A
	A[y][x] = 0
	if x < W-1 and A[y][x+1] == s: fill0(s,x+1,y)
	if y < H-1 and A[y+1][x] == s: fill0(s,x,y+1)
	if x > 0   and A[y][x-1] == s: fill0(s,x-1,y)
	if y > 0   and A[y-1][x] == s: fill0(s,x,y-1)

while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	ans = 0
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				fill0(A[y][x],x,y)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count