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


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)


Fixed submission:
from collections import deque


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)

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


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)


Fixed submission:
from collections import deque


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)

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


H, W = map(int, input().split())
A = [input() for _ in range(H)]
m = [[3000] * W for _ in range(H)]
for i, s in enumerate(A):
    for j, c in enumerate(s):
        if c == '#':
            m[i][j] = 0


def bfs(i, j):
    queue = deque()
    queue.append((i, j))
    while queue:
        p, q = queue.popleft()
        if 0 < p and m[p - 1][q] > m[p][q] + 1:
            m[p - 1][q] = m[p][q] + 1
            queue.append((p - 1, q))
        if 0 < q and m[p][q - 1] > m[p][q] + 1:
            m[p][q - 1] = m[p][q] + 1
            queue.append((p, q - 1))
        if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
            m[p + 1][q] = m[p][q] + 1
            queue.append((p + 1, q))
        if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
            m[p][q + 1] = m[p][q] + 1
            queue.append((p, q + 1))


for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            bfs(i, j)
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)


Fixed submission:
from collections import deque


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)

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


H, W = map(int, input().split())
A = [input() for _ in range(H)]
m = [[3000] * W for _ in range(H)]


def bfs(i, j):
    queue = deque()
    queue.append((i, j))
    while queue:
        p, q = queue.popleft()
        if 0 < p and A[p - 1][q] == '.' and m[p - 1][q] > m[p][q] + 1:
            m[p - 1][q] = m[p][q] + 1
            queue.append((p - 1, q))
        if 0 < q and A[p][q - 1] == '.' and m[p][q - 1] > m[p][q] + 1:
            m[p][q - 1] = m[p][q] + 1
            queue.append((p, q - 1))
        if p < H - 1 and A[p + 1][q] == '.' and m[p + 1][q] > m[p][q] + 1:
            m[p + 1][q] = m[p][q] + 1
            queue.append((p + 1, q))
        if q < W - 1 and A[p][q + 1] == '.' and m[p][q + 1] > m[p][q] + 1:
            m[p][q + 1] = m[p][q] + 1
            queue.append((p, q + 1))


for i, s in enumerate(A):
    for j, c in enumerate(s):
        if c == '#':
            m[i][j] = 0
            bfs(i, j)
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)


Fixed submission:
from collections import deque


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)

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


H, W = map(int, input().split())
A = [input() for _ in range(H)]
m = [[float('inf')] * W for _ in range(H)]


def bfs(i, j):
    queue = deque()
    queue.append((i, j))
    while queue:
        p, q = queue.popleft()
        if 0 < p and A[p - 1][q] == '.' and m[p - 1][q] > m[p][q] + 1:
            m[p - 1][q] = m[p][q] + 1
            queue.append((p - 1, q))
        if 0 < q and A[p][q - 1] == '.' and m[p][q - 1] > m[p][q] + 1:
            m[p][q - 1] = m[p][q] + 1
            queue.append((p, q - 1))
        if p < H - 1 and A[p + 1][q] == '.' and m[p + 1][q] > m[p][q] + 1:
            m[p + 1][q] = m[p][q] + 1
            queue.append((p + 1, q))
        if q < W - 1 and A[p][q + 1] == '.' and m[p][q + 1] > m[p][q] + 1:
            m[p][q + 1] = m[p][q] + 1
            queue.append((p, q + 1))


for i, s in enumerate(A):
    for j, c in enumerate(s):
        if c == '#':
            m[i][j] = 0
            bfs(i, j)
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)


Fixed submission:
from collections import deque


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)

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


H, W = map(int, input().split())
A = [input() for _ in range(H)]
m = [[float('inf')] * W for _ in range(H)]


def bfs(i, j):
    queue = deque()
    queue.append((i, j))
    while queue:
        p, q = queue.popleft()
        if 0 < p and A[p - 1][q] == '.' and m[p - 1][q] > m[p][q] + 1:
            m[p - 1][q] = m[p][q] + 1
            queue.append((p - 1, q))
        if 0 < q and A[p][q - 1] == '.' and m[p][q - 1] > m[p][q] + 1:
            m[p][q - 1] = m[p][q] + 1
            queue.append((p, q - 1))
        if p < H - 1 and A[p + 1][q] == '.' and m[p + 1][q] > m[p][q] + 1:
            m[p + 1][q] = m[p][q] + 1
            queue.append((p + 1, q))
        if q < W - 1 and A[p][q + 1] == '.' and m[p][q + 1] > m[p][q] + 1:
            m[p][q + 1] = m[p][q] + 1
            queue.append((p, q + 1))


for i, s in enumerate(A):
    for j, c in enumerate(s):
        if c == '#':
            m[i][j] = 0
            bfs(i, j)
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)


Fixed submission:
from collections import deque


H, W = map(int, input().split())
m = [[0 if c == '#' else 3000 for c in input()] for _ in range(H)]
queue = deque()
for i, r in enumerate(m):
    for j, n in enumerate(r):
        if n == 0:
            queue.append((i, j))
while queue:
    p, q = queue.popleft()
    if 0 < p and m[p - 1][q] > m[p][q] + 1:
        m[p - 1][q] = m[p][q] + 1
        queue.append((p - 1, q))
    if 0 < q and m[p][q - 1] > m[p][q] + 1:
        m[p][q - 1] = m[p][q] + 1
        queue.append((p, q - 1))
    if p < H - 1 and m[p + 1][q] > m[p][q] + 1:
        m[p + 1][q] = m[p][q] + 1
        queue.append((p + 1, q))
    if q < W - 1 and m[p][q + 1] > m[p][q] + 1:
        m[p][q + 1] = m[p][q] + 1
        queue.append((p, q + 1))
_max = 0
for r in m:
    _max = max(_max, max(r))
print(_max)