Buggy python submission (verdict: Runtime Error):
def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans

Buggy python submission (verdict: Runtime Error):
dxy = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
def solve(w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == 1:
		field[h][w] = 0
		for dx,dy in dxy:
			solve(w+dx,h+dy)

while 1:
	W,H = map(int,raw_input().split())
	if W == 0: break
	field = [map(int,raw_input().split()) for i in range(H)]
	ans = 0
	for h in range(H):
		for w in range(W):
			if field[h][w] == 1:
				solve(w,h)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans

Buggy python submission (verdict: Runtime Error):
global field
dxy = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
def solve(w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == 1:
		field[h][w] = 0
		for dx,dy in dxy:
			solve(w+dx,h+dy)

while 1:
	W,H = map(int,raw_input().split())
	if W == 0: break
	field = [map(int,raw_input().split()) for i in range(H)]
	ans = 0
	for h in range(H):
		for w in range(W):
			if field[h][w] == 1:
				solve(w,h)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans

Buggy python submission (verdict: Runtime Error):
dxy = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
def solve(field,w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == 1:
		field[h][w] = 0
		for dx,dy in dxy:
			solve(field,w+dx,h+dy)

while 1:
	W,H = map(int,raw_input().split())
	if W == 0: break
	field = [map(int,raw_input().split()) for i in range(H)]
	ans = 0
	for h in range(H):
		for w in range(W):
			if field[h][w] == 1:
				solve(field,w,h)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans

Buggy python submission (verdict: Runtime Error):
dxy = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
def solve(field,w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == 1:
		field[h][w] = 0
		for dx,dy in dxy:
			solve(field,w+dx,h+dy)
		return 1
	else:
		return 0

while 1:
	W,H = map(int,raw_input().split())
	if W == 0: break
	field = [map(int,raw_input().split()) for i in range(H)]
	ans = 0
	for h in range(H):
		for w in range(W):
			if field[h][w] == 1:
				solve(field,w,h)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans

Buggy python submission (verdict: Runtime Error):
dwh = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
def solve(field,w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == 1:
		field[h][w] = 0
		for dw,dh in dwh:
			solve(field,w+dw,h+dh)

while 1:
	W,H = map(int,raw_input().split())
	if W == 0: break
	field = [map(int,raw_input().split()) for i in range(H)]
	ans = 0
	for h in range(H):
		for w in range(W):
			if field[h][w] == 1:
				solve(field,w,h)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans

Buggy python submission (verdict: Runtime Error):
dwh = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
def solve(field,w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == 1:
		field[h][w] = 0
		for dw,dh in dwh:
			solve(field,w+dw,h+dh)
	return

while 1:
	W,H = map(int,raw_input().split())
	if W == 0: break
	field = [map(int,raw_input().split()) for i in range(H)]
	ans = 0
	for h in range(H):
		for w in range(W):
			if field[h][w] == 1:
				solve(field,w,h)
				ans += 1
	print ans

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans