Buggy python submission (verdict: Runtime Error):
def dfs(x,y,ch):
	field[x][y] = '.'
	for i in range(4):
			nx = x+moveY[i]
			ny = y+moveX[i]
			if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					dfs(nx,ny,field[nx][ny])
if __name__ == '__main__':
	moveY = [-1,0,1,0]
	moveX = [0,1,0,-1]
	H,W = map(int,raw_input().split(' '))
	field = ['' for i in range(H)]
	h = 0
	while True:
		s = raw_input()
		if s == '0 0':
			break
		field[h] = list(s)
		h += 1
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Buggy python submission (verdict: Runtime Error):
def dfs(x,y,ch):
	field[x][y] = '.'
	for i in range(4):
			nx = x+moveY[i]
			ny = y+moveX[i]
			if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					dfs(nx,ny,field[nx][ny])
if __name__ == '__main__':
	moveY = [-1,0,1,0]
	moveX = [0,1,0,-1]
	H,W = map(int,raw_input().split(' '))
	field = ['' for i in range(H)]
	h = 0
	while True:
		s = raw_input()
		if s == '0 0':
			break
		field[h] = list(s)
		h += 1
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Buggy python submission (verdict: Runtime Error):
def dfs(x,y,ch):
	field[x][y] = '.'
	for i in range(4):
			nx = x+moveY[i]
			ny = y+moveX[i]
			if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					dfs(nx,ny,field[nx][ny])
if __name__ == '__main__':
	moveY = [-1,0,1,0]
	moveX = [0,1,0,-1]
	H,W = map(int,raw_input().split(' '))
	field = ['' for i in range(H)]
	h = 0
	while True:
		s = raw_input()
		if s == '0 0':
			break
		field[h] = list(s)
		h += 1
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Buggy python submission (verdict: Runtime Error):
def dfs(x,y,ch):
	field[x][y] = '.'
	for i in range(4):
			nx = x+moveY[i]
			ny = y+moveX[i]
			if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					dfs(nx,ny,field[nx][ny])
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
H,W = map(int,raw_input().split(' '))
field = ['' for i in range(H)]
h = 0
while True:
	s = raw_input()
	if s == '0 0':
		break
	field[h] = list(s)
	h += 1
correct =0
for i in range(H):
	for j in range(W):
		if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
			dfs(i,j,field[i][j])
			correct += 1
print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Buggy python submission (verdict: Runtime Error):
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) != 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
					if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
						field[nx][ny] = '.'
						stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
H,W = map(int,raw_input().split(' '))
field = ['' for i in range(H)]
h = 0
while True:
	s = raw_input()
	if s == '0 0':
		break
	field[h] = list(s)
	h += 1
correct =0
for i in range(H):
	for j in range(W):
		if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
			dfs(i,j,field[i][j])
			correct += 1
print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Buggy python submission (verdict: Runtime Error):
def dfs(X,Y,ch):
	stack.append([X,Y])
	print stack
	field[X][Y] = '.'
	while len(stack) != 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
					if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
						field[nx][ny] = '.'
						stack.append([nx,ny])
						print stack
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = ['' for i in range(H)]
	h = 0
	while True:
		field[h] = list(raw_input())
		h += 1
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Buggy python submission (verdict: Time Limit Exceeded):
def dfs(X,Y,ch):
	stack.append([X,Y])
	print stack
	field[X][Y] = '.'
	while len(stack) != 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
					if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
						field[nx][ny] = '.'
						stack.append([nx,ny])
						print stack
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = ['' for i in range(H)]
	h = 0
	for i in range(H):
		field[i] = list(raw_input())
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Buggy python submission (verdict: Runtime Error):
def dfs(X,Y,ch):
	field[X][Y] = '.'
	for i in range(4):
		nx = X+moveY[i]
		ny = Y+moveX[i]
		if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
			if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
				dfs(nx,ny,field[nx][ny])
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	print field
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct

Fixed submission:
def dfs(X,Y,ch):
	stack.append([X,Y])
	field[X][Y] = '.'
	while len(stack) > 0:
		x,y = stack.pop()
		for i in range(4):
				nx = x+moveY[i]
				ny = y+moveX[i]
				if nx < 0 or ny < 0 or nx >= H or ny >= W or field[nx][ny] != ch:
					continue
				if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
					field[nx][ny] = '.'
					stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
	H,W = map(int,raw_input().split(' '))
	if H == 0 and W == 0:
		break
	field = [list(raw_input()) for i in range(H)]
	correct =0
	for i in range(H):
		for j in range(W):
			if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
				dfs(i,j,field[i][j])
				correct += 1
	print correct