Buggy python submission (verdict: Runtime Error):
def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count