Buggy python submission (verdict: Time Limit Exceeded):
#import sys
import heapq
#import copy
#import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
a=[['.']*w for i in range(h)]
q=deque()
cnt=0
for i in range(h):
    for j,x in enumerate(input()):
        if x=='#':
            deque.append(q,[i,j])
            a[i][j]=0

while len(q)>0:
    hh,ww=deque.popleft(q)

    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        
        if 0>nh or nh>=h or 0>nw or nw>=w or a[nh][nw]!='.':
            continue
        
        a[nh][nw]=a[hh][ww]+1
        cnt=max(cnt,a[nh][nw])

        deque.append(q,[nh,nw])

print(cnt)


Fixed submission:
from collections import deque

h,w=list(map(int,input().split()))
a=[[c for c in input()] for _ in range(h)]
visit=[[0]*w for _ in range(h)]
q=deque()

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            deque.appendleft(q,(i,j,0))
            visit[i][j]=1
ans=0
while len(q)>0:
    i,j,cnt=deque.pop(q)

    ans=max(ans,cnt)

    for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]:
        ni=i+di
        nj=j+dj
        if 0<=ni<h and 0<=nj<w and visit[ni][nj]==0:
            visit[ni][nj]=1
            deque.appendleft(q,(ni,nj,cnt+1))

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
import heapq
import copy
import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
a=[['.']*w for i in range(h)]
q=deque()
cnt=0
for i in range(h):
    for j,x in enumerate(sys.stdin.readline().strip()):
        if x=='#':
            deque.append(q,[i,j])
            a[i][j]=0

while len(q)>0:
    hh,ww=deque.popleft(q)

    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        
        if 0>nh or nh>=h or 0>nw or nw>=w or a[nh][nw]!='.':
            continue
        
        a[nh][nw]=a[hh][ww]+1
        cnt=max(cnt,a[nh][nw])

        deque.append(q,[nh,nw])

print(cnt)


Fixed submission:
from collections import deque

h,w=list(map(int,input().split()))
a=[[c for c in input()] for _ in range(h)]
visit=[[0]*w for _ in range(h)]
q=deque()

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            deque.appendleft(q,(i,j,0))
            visit[i][j]=1
ans=0
while len(q)>0:
    i,j,cnt=deque.pop(q)

    ans=max(ans,cnt)

    for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]:
        ni=i+di
        nj=j+dj
        if 0<=ni<h and 0<=nj<w and visit[ni][nj]==0:
            visit[ni][nj]=1
            deque.appendleft(q,(ni,nj,cnt+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
import copy
import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
a=[['.']*w for i in range(h)]
q=deque()
cnt=0
for i in range(h):
    for j,x in enumerate(sys.stdin.readline().strip()):
        if x=='#':
            deque.append(q,[i,j])
            a[i][j]=0

while len(q)>0:
    hh,ww=deque.popleft(q)

    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        
        if 0>nh or nh>=h or 0>nw or nw>=w or a[nh][nw]!='.':
            continue
        
        a[nh][nw]=a[hh][ww]+1
        cnt=max(cnt,a[nh][nw])

        deque.append(q,[nh,nw])

print(cnt)


Fixed submission:
from collections import deque

h,w=list(map(int,input().split()))
a=[[c for c in input()] for _ in range(h)]
visit=[[0]*w for _ in range(h)]
q=deque()

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            deque.appendleft(q,(i,j,0))
            visit[i][j]=1
ans=0
while len(q)>0:
    i,j,cnt=deque.pop(q)

    ans=max(ans,cnt)

    for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]:
        ni=i+di
        nj=j+dj
        if 0<=ni<h and 0<=nj<w and visit[ni][nj]==0:
            visit[ni][nj]=1
            deque.appendleft(q,(ni,nj,cnt+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
import copy
import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
a=[['.']*w for i in range(h)]
q=deque()
cnt=0
for i in range(h):
    for j,x in enumerate(input()):
        if x=='#':
            deque.append(q,[i,j])
            a[i][j]=0

while len(q)>0:
    hh,ww=deque.popleft(q)

    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        
        if 0>nh or nh>=h or 0>nw or nw>=w or a[nh][nw]!='.':
            continue
        
        a[nh][nw]=a[hh][ww]+1
        cnt=max(cnt,a[nh][nw])

        deque.append(q,[nh,nw])

print(cnt)


Fixed submission:
from collections import deque

h,w=list(map(int,input().split()))
a=[[c for c in input()] for _ in range(h)]
visit=[[0]*w for _ in range(h)]
q=deque()

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            deque.appendleft(q,(i,j,0))
            visit[i][j]=1
ans=0
while len(q)>0:
    i,j,cnt=deque.pop(q)

    ans=max(ans,cnt)

    for di,dj in [(-1,0),(1,0),(0,-1),(0,1)]:
        ni=i+di
        nj=j+dj
        if 0<=ni<h and 0<=nj<w and visit[ni][nj]==0:
            visit[ni][nj]=1
            deque.appendleft(q,(ni,nj,cnt+1))

print(ans)