Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
def main():
    H,W = list(map(int,sys.stdin.readline().split()))
    A = [sys.stdin.readline().split() for i in range(H)]
    place_h = [0,-1,0,1]
    place_w = [1,0,-1,0]
    black = 0
    q = []
    dist = []
    for i in range(H):
        A[i] = list(A[i][0])
        dist_sub = []
        for j in range(W):
            if A[i][j] == "#":
                black += 1
                q.append(deque([[i,j]]))
                dist_sub.append(0)
            else:
                dist_sub.append(-1)
        dist.append(dist_sub)

    ans = 0
    count=0
    while count < black:
        for i in range(black):
            if len(q[i]) == 0:
                count += 1
                q[i].append(-1)
                continue
            if q[i][0] == -1:
                continue
            vh,vw = q[i].popleft()
            for m in range(4):
                nvh = vh+place_h[m]
                nvw = vw+place_w[m]
                if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                    q[i].append([nvh,nvw])
                    dist[nvh][nvw] = dist[vh][vw]+1
                    if ans < dist[nvh][nvw]:
                        ans = dist[nvh][nvw]

    print(ans)

if __name__ == "__main__":
    main()




Fixed submission:
from collections import deque
import sys
def main():
    H,W = list(map(int,sys.stdin.readline().split()))
    place_h = [0,-1,0,1]
    place_w = [1,0,-1,0]
    black = 0
    q = deque([])
    dist = []
    A = []
    for i in range(H):
        a = sys.stdin.readline().split()
        a = list(a[0])
        dist_sub = []
        for j in range(W):
            if a[j] == "#":
                black += 1
                q.append([i,j])
                dist_sub.append(0)
            else:
                dist_sub.append(-1)
        A.append(a)
        dist.append(dist_sub)

    ans = 0
    
    while len(q) > 0:
        vh,vw = q.popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q.append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
                if ans < dist[nvh][nvw]:
                    ans = dist[nvh][nvw]

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy
H,W = list(map(int,input().split()))
A = [input().split() for i in range(H)]
place_h = [0,-1,0,1]
place_w = [1,0,-1,0]
black = 0
q = []
dist = [[-1 for i in range(W)] for j in range(H)]
for i in range(H):
    A[i] = list(A[i][0])
    for j in range(W):
        if A[i][j] == "#":
            black += 1
            q.append(deque([[i,j]]))
            dist[i][j] = 0

while len(q)>0:
    i = 0
    while i < black:
        if len(q[i]) == 0:
            q.pop(i)
            black -= 1
            continue
        vh,vw = q[i].popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q[i].append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
        i+=1
print(numpy.amax(dist))





Fixed submission:
from collections import deque
import sys
def main():
    H,W = list(map(int,sys.stdin.readline().split()))
    place_h = [0,-1,0,1]
    place_w = [1,0,-1,0]
    black = 0
    q = deque([])
    dist = []
    A = []
    for i in range(H):
        a = sys.stdin.readline().split()
        a = list(a[0])
        dist_sub = []
        for j in range(W):
            if a[j] == "#":
                black += 1
                q.append([i,j])
                dist_sub.append(0)
            else:
                dist_sub.append(-1)
        A.append(a)
        dist.append(dist_sub)

    ans = 0
    
    while len(q) > 0:
        vh,vw = q.popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q.append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
                if ans < dist[nvh][nvw]:
                    ans = dist[nvh][nvw]

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import numpy
H,W = list(map(int,input().split()))
A = [input().split() for i in range(H)]
place_h = [0,-1,0,1]
place_w = [1,0,-1,0]
black = 0
q = []
dist = [[-1 for i in range(W)] for j in range(H)]
for i in range(H):
    A[i] = list(A[i][0])
    for j in range(W):
        if A[i][j] == "#":
            black += 1
            q.append(deque([[i,j]]))
            dist[i][j] = 0

while len(q)>0:
    i = 0
    while i < black:
        if len(q[i]) == 0:
            q.pop(i)
            black -= 1
            continue
        vh,vw = q[i].popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q[i].append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
        i+=1
print(numpy.amax(dist))





Fixed submission:
from collections import deque
import sys
def main():
    H,W = list(map(int,sys.stdin.readline().split()))
    place_h = [0,-1,0,1]
    place_w = [1,0,-1,0]
    black = 0
    q = deque([])
    dist = []
    A = []
    for i in range(H):
        a = sys.stdin.readline().split()
        a = list(a[0])
        dist_sub = []
        for j in range(W):
            if a[j] == "#":
                black += 1
                q.append([i,j])
                dist_sub.append(0)
            else:
                dist_sub.append(-1)
        A.append(a)
        dist.append(dist_sub)

    ans = 0
    
    while len(q) > 0:
        vh,vw = q.popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q.append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
                if ans < dist[nvh][nvw]:
                    ans = dist[nvh][nvw]

    print(ans)

if __name__ == "__main__":
    main()