Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
h,w=map(int,input().split())
A=[[False]*(w+2) for _ in range(h+2)]
chk,chk2=[],[]
for i in range(h):
  s=input()
  for j in range(w):
    A[i+1][j+1]=(s[j]==".")
    if s[j]=="#":
      chk.append((i+1,j+1))
ans=0
d=((1,0),(0,1),(-1,0),(0,-1))
while chk:
  for cx,cy in chk:
    for dx, dy in d:
      if A[cx+dx][cy+dy]==True:
        chk2.append((cx+dx,cy+dy))
        A[cx+dx][cy+dy]=False
  if chk2:
    ans+=1
  chk=chk2
  chk2=[]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
h,w=map(int,input().split())
A=[[False]*(w+2) for _ in range(h+2)]
chk,chk2=[],[]
for i in range(h):
  s=input()
  for j in range(w):
    A[i+1][j+1]=(s[j]==".")
    if s[j]=="#":
      chk.append((i+1,j+1))
ans=0
d=((1,0),(0,1),(-1,0),(0,-1))
while chk:
  for cx,cy in chk:
    for dx, dy in d:
      if A[cx+dx][cy+dy]==True:
        chk2.append((cx+dx,cy+dy))
        A[cx+dx][cy+dy]=False
  if chk2:
    ans+=1
  chk=chk2
  chk2=[]
print(ans)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B=[]
for i in range(w):
  for j in range(h):
    if A[i][j]=="#":
      B.append([i,j])
ans=0
for i in range(w):
  for j in range(h):
    if [i,j] not in B:
      d=min(abs(i-b[0])+abs(j-b[1]) for b in B)     
      ans=max(d,ans)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
h,w=map(int,input().split())
A=[[False]*(w+2) for _ in range(h+2)]
chk,chk2=[],[]
for i in range(h):
  s=input()
  for j in range(w):
    A[i+1][j+1]=(s[j]==".")
    if s[j]=="#":
      chk.append((i+1,j+1))
ans=0
d=((1,0),(0,1),(-1,0),(0,-1))
while chk:
  for cx,cy in chk:
    for dx, dy in d:
      if A[cx+dx][cy+dy]==True:
        chk2.append((cx+dx,cy+dy))
        A[cx+dx][cy+dy]=False
  if chk2:
    ans+=1
  chk=chk2
  chk2=[]
print(ans)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B,T=set(),set()
for i in range(w):
  for j in range(h):
    T.add((i,j))
    if A[i][j]=="#":
      B.add((i,j))
T-=B
count=0
while len(T)>0:
  C=set()
  for b in B:
    if b[0]>0:
      C.add((b[0]-1,b[1]))
    if b[1]<w-1:
      C.add((b[0],b[1]+1))
    if b[0]<h-1:
      C.add((b[0]+1,b[1]))
    if b[1]>0:
      C.add((b[0],b[1]-1))
  T-=C
  B=C
  count+=1
print(count)

Fixed submission:
import sys
input = sys.stdin.readline
h,w=map(int,input().split())
A=[[False]*(w+2) for _ in range(h+2)]
chk,chk2=[],[]
for i in range(h):
  s=input()
  for j in range(w):
    A[i+1][j+1]=(s[j]==".")
    if s[j]=="#":
      chk.append((i+1,j+1))
ans=0
d=((1,0),(0,1),(-1,0),(0,-1))
while chk:
  for cx,cy in chk:
    for dx, dy in d:
      if A[cx+dx][cy+dy]==True:
        chk2.append((cx+dx,cy+dy))
        A[cx+dx][cy+dy]=False
  if chk2:
    ans+=1
  chk=chk2
  chk2=[]
print(ans)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B=set()
for i in range(w):
  for j in range(h):
    if A[i][j]=="#":
      B.add((i,j))
count=0
while len(B)<h*w:
  C=set()
  for b in B:
    if b[0]>0:
      C.add((b[0]-1,b[1]))
    if b[1]<w-1:
      C.add((b[0],b[1]+1))
    if b[0]<h-1:
      C.add((b[0]+1,b[1]))
    if b[1]>0:
      C.add((b[0],b[1]-1))
  B=B.union(C)
  count+=1
print(count)

Fixed submission:
import sys
input = sys.stdin.readline
h,w=map(int,input().split())
A=[[False]*(w+2) for _ in range(h+2)]
chk,chk2=[],[]
for i in range(h):
  s=input()
  for j in range(w):
    A[i+1][j+1]=(s[j]==".")
    if s[j]=="#":
      chk.append((i+1,j+1))
ans=0
d=((1,0),(0,1),(-1,0),(0,-1))
while chk:
  for cx,cy in chk:
    for dx, dy in d:
      if A[cx+dx][cy+dy]==True:
        chk2.append((cx+dx,cy+dy))
        A[cx+dx][cy+dy]=False
  if chk2:
    ans+=1
  chk=chk2
  chk2=[]
print(ans)