Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.append([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)


Fixed submission:
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.append([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.spatial.distance import cityblock
B = []
Distance = []

H,W = map(int,input().split())
minD = 0
for row in range(H):
    Inputs = list(input())
    for column in [i for i, x in enumerate(Inputs) if x == '#']:
        B.append((column,row))

for column in range(W):
    for row in range(H):
        Distance = []
        a = (column,row)
        for b in B:
            Manhattan = cityblock(a,b)
            if Manhattan > minD:
                Distance.append(Manhattan)
            else:
                break
        if len(Distance) == len(B):
            if min(Distance) > minD:
                minD = min(Distance)
print(minD)

Fixed submission:
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.append([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.spatial.distance import cityblock
B = []

H,W = map(int,input().split())
for row in range(H):
    Inputs = input().split()
    for column in [i for i, x in enumerate(Inputs) if x == '#']:
        B.append((column,row))
OO = [cityblock((0,0),b) for b in B]
OI = [cityblock((0,W-1),b) for b in B]
IO = [cityblock((H-1,0),b) for b in B]
II = [cityblock((H-1,W-1),b) for b in B]
print(min(min(OO),min(OI),min(IO),min(II)))

Fixed submission:
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.append([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.spatial.distance import cityblock
H,W = map(int,input().split())
for row in range(H):
    Inputs = input().split(',')
    for column in [i for i, x in enumerate(Inputs) if x == '#']:
        B.append((column,row))
for b in B:
    OO.apppend(cityblock((0,0),b))
    OI.apppend(cityblock((H-1,0),b))
    IO.apppend(cityblock((0,W-1),b))
    II.append(cityblock(H-1,W-1,b))
print(min(min(OO),min(OI),min(IO),min(II)))

Fixed submission:
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.append([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)