Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = [[True]*H for i in [0]*W]
for x,y in bk:
	mat[x][y] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1][y]:
			mat[x-1][y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1][y]:
			new.append((x+1,y))
			mat[x+1][y] = False
		if y > 0 and mat[x][y-1]:
			new.append((x,y-1))
			mat[x][y-1] = False
		if y < H-1 and mat[x][y+1]:
			new.append((x,y+1))
			mat[x][y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)




Fixed submission:
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = [[True]*H for i in [0]*W]
for x,y in bk:
	mat[x][y] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1][y]:
			mat[x-1][y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1][y]:
			new.append((x+1,y))
			mat[x+1][y] = False
		if y > 0 and mat[x][y-1]:
			new.append((x,y-1))
			mat[x][y-1] = False
		if y < H-1 and mat[x][y+1]:
			new.append((x,y+1))
			mat[x][y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = np.ones((W,H)).astype(np.bool)
for p in bk:
	mat[p] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1,y]:
			mat[x-1,y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1,y]:
			new.append((x+1,y))
			mat[x+1,y] = False
		if y > 0 and mat[x,y-1]:
			new.append((x,y-1))
			mat[x,y-1] = False
		if y < H-1 and mat[x,y+1]:
			new.append((x,y+1))
			mat[x,y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)




Fixed submission:
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = [[True]*H for i in [0]*W]
for x,y in bk:
	mat[x][y] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1][y]:
			mat[x-1][y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1][y]:
			new.append((x+1,y))
			mat[x+1][y] = False
		if y > 0 and mat[x][y-1]:
			new.append((x,y-1))
			mat[x][y-1] = False
		if y < H-1 and mat[x][y+1]:
			new.append((x,y+1))
			mat[x][y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = np.zeros((W,H)).astype(np.bool)
for p in bk:
	mat[p] = True

cnt = 0
red = bk[:]
al  =len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in red:
		if x > 0 and not mat[x-1,y]:
			mat[x-1,y] = True
			new.append((x-1,y))
		if x < W-1 and not mat[x+1,y]:
			new.append((x+1,y))
			mat[x+1,y] = True
		if y > 0 and not mat[x,y-1]:
			new.append((x,y-1))
			mat[x,y-1] = True
		if y < H-1 and not mat[x,y+1]:
			new.append((x,y+1))
			mat[x,y+1] = True
	red = new[:]
	al += len(new)
	cnt += 1
print(cnt)




Fixed submission:
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = [[True]*H for i in [0]*W]
for x,y in bk:
	mat[x][y] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1][y]:
			mat[x-1][y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1][y]:
			new.append((x+1,y))
			mat[x+1][y] = False
		if y > 0 and mat[x][y-1]:
			new.append((x,y-1))
			mat[x][y-1] = False
		if y < H-1 and mat[x][y+1]:
			new.append((x,y+1))
			mat[x][y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

obk = set()
bk = set(bk)
cnt = 0
al = len(bk)
red = bk.copy()
while(True):
	if al == H*W:
		break
	new = set()
	for x,y in red:
		if x > 0:
			new.add((x-1,y))
		if x < W-1:
			new.add((x+1,y))
		if y > 0:
			new.add((x,y-1))
		if y < H-1:
			new.add((x,y+1))
	new -= bk
	red = new.copy()
	bk |= new
	al += len(new)
	cnt += 1
print(cnt)




Fixed submission:
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = [[True]*H for i in [0]*W]
for x,y in bk:
	mat[x][y] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1][y]:
			mat[x-1][y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1][y]:
			new.append((x+1,y))
			mat[x+1][y] = False
		if y > 0 and mat[x][y-1]:
			new.append((x,y-1))
			mat[x][y-1] = False
		if y < H-1 and mat[x][y+1]:
			new.append((x,y+1))
			mat[x][y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import itertools
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(i,x) for x in range(W) if t[x] == '#'])
bk = np.array(bk)

ans = np.zeros((H,W)).astype(np.int)
for pos in itertools.product(range(H),range(W)):
	ans[pos] = np.min(np.linalg.norm(bk-pos,ord=1,axis=1))
print(np.max(ans))







Fixed submission:
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = [[True]*H for i in [0]*W]
for x,y in bk:
	mat[x][y] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1][y]:
			mat[x-1][y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1][y]:
			new.append((x+1,y))
			mat[x+1][y] = False
		if y > 0 and mat[x][y-1]:
			new.append((x,y-1))
			mat[x][y-1] = False
		if y < H-1 and mat[x][y+1]:
			new.append((x,y+1))
			mat[x][y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(i,x) for x in range(W) if t[x] == '#'])

ans = -1

for y in range(H):
	for x in range(W):
		t = min([abs(x-x2)+abs(y-y2) for y2,x2 in bk])
		ans = max(t,ans)

print(ans)



Fixed submission:
H,W = map(int,input().split(' '))
bk = []
for i in range(H):
	t = input()
	bk.extend([(x,i) for x in range(W) if t[x] == '#'])

mat = [[True]*H for i in [0]*W]
for x,y in bk:
	mat[x][y] = False

cnt = 0
al = len(bk)
while(True):
	if al == H*W:
		break
	new = []
	for x,y in bk:
		if x > 0 and mat[x-1][y]:
			mat[x-1][y] = False
			new.append((x-1,y))
		if x < W-1 and mat[x+1][y]:
			new.append((x+1,y))
			mat[x+1][y] = False
		if y > 0 and mat[x][y-1]:
			new.append((x,y-1))
			mat[x][y-1] = False
		if y < H-1 and mat[x][y+1]:
			new.append((x,y+1))
			mat[x][y+1] = False
	al += len(new)
	bk = new
	cnt += 1
print(cnt)