Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)


Fixed submission:
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [[_ for _ in input()] for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        A[i][j] = 0
        Q += [[i, j]]
while Q:
    i, j = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W:
            if A[ni][nj] == '.':
                A[ni][nj] = A[i][j] + 1
                Q += [[ni, nj]]
print(max(max(_) for _ in A))


Fixed submission:
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [[_ for _ in input()] for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        A[i][j] = 0
        Q += [[i, j]]
while Q:
    i, j = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W:
            if A[ni][nj] == '.':
                A[ni][nj] = A[i][j] + 1
                Q += [[ni, nj]]
print(max(max(_) for _ in A))


Fixed submission:
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [[_ for _ in input()] for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        A[i][j] = 0
        Q += [[i, j]]
while Q:
    i, j = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W:
            if A[ni][nj] == '.':
                A[ni][nj] = A[i][j] + 1
                Q += [[ni, nj]]
print(max(max(_) for _ in A))


Fixed submission:
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

H, W = [int(_) for _ in input().split()]
A = [[_ for _ in input()] for _ in range(H)]
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        A[i][j] = 0
        break
stack = [[i, j]]
while stack:
    i, j = stack.pop()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W:
            if A[ni][nj] == '#':
                A[ni][nj] = 0
                stack += [[ni, nj]]
            elif A[ni][nj] == '.' or A[i][j] + 1 < A[ni][nj]:
                A[ni][nj] = A[i][j] + 1
                stack += [[ni, nj]]
print(max(max(_) for _ in A))


Fixed submission:
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)

Buggy python submission (verdict: Runtime Error):
import itertools

H, W = [int(_) for _ in input().split()]
A = [[_ for _ in input()] for _ in range(H)]
D = []
S = []
for x, y in itertools.product(range(H), range(W)):
    if A[x][y] == '.':
        D += [[x, y]]
    else:
        S += [[x, y]]

print(max(min([abs(X - x) + abs(Y - y) for x, y in S]) for X, Y in D))


Fixed submission:
import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)