Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
H,W=map(int, input().split())
A=[[-1]*W for _ in range(H)]
d=deque()
for h in range(H):
  s=input()
  for w in range(W):
    if s[w]=='.':
      pass
    else:
      A[h][w]=0
      d.append((h,w))

DIF=[(1,0),(0,1),(-1,0),(0,-1)]
while d:
  point=d.popleft()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      d.append((x,y))
      A[x][y]=A[point[0]][point[1]]+1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
H,W=map(int, input().split())
A=[[-1]*W for _ in range(H)]
d=[]
for h in range(H):
  s=input()
  for w in range(W):
    if s[w]=='.':
      pass
    else:
      A[h][w]=0
      d.append((h,w))

cnt=1
DIF=[(1,0),(0,1),(-1,0),(0,-1)]
tmp=[]
while d:
  point=d.pop()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      tmp.append((x,y))
      A[x][y]=cnt
  if not d:
    #print(tmp)
    d=copy.deepcopy(tmp)
    tmp=[]
    #print(d)
    cnt+=1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
def main():
  H,W=map(int, input().split())
  A=[]
  d=[]
  for h in range(H):
    a=[]
    s=input()
    for w in range(W):
      if s[w]=='.':
        a.append(-1)
      else:
        a.append(0)
        d.append((h,w))
    A.append(a)
  cnt=1
  DIF=[(1,0),(0,1),(-1,0),(0,-1)]
  tmp=[]
  while d:
    point=d.pop()
    for dif in DIF:
      x=point[0]+dif[0]
      y=point[1]+dif[1]
      if 0<=x<H and 0<=y<W and A[x][y]==-1:
        tmp.append((x,y))
        A[x][y]=cnt
    if not d:
      #print(tmp)
      d=copy.deepcopy(tmp)
      tmp=[]
      #print(d)
      cnt+=1
  ans=0    
  for h in range(H):
    Amax=max(A[h])
    ans=max(ans,Amax)
  #print(A)
  print(ans)
if __name__=='__main__':
  main()

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
H,W=map(int, input().split())
A=[]
d=[]
for h in range(H):
  a=[]
  s=input()
  for w in range(W):
    if s[w]=='.':
      a.append(-1)
    else:
      a.append(0)
      d.append((h,w))
  A.append(a)
cnt=1
DIF=[(1,0),(0,1),(-1,0),(0,-1)]
tmp=[]
while d:
  point=d.pop()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      tmp.append((x,y))
      A[x][y]=cnt
  if not d:
    #print(tmp)
    d=copy.deepcopy(tmp)
    tmp=[]
    #print(d)
    cnt+=1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
H,W=map(int, input().split())
A=[]
d=deque()
for h in range(H):
  a=[]
  s=input()
  for w in range(W):
    if s[w]=='.':
      a.append(-1)
    else:
      a.append(0)
      d.append((h,w))
  A.append(a)
cnt=1
DIF=[(1,0),(0,1),(-1,0),(0,-1)]
tmp=deque()
while d:
  point=d.popleft()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      tmp.append((x,y))
      A[x][y]=cnt
  if not d:
    #print(tmp)
    d=copy.deepcopy(tmp)
    tmp=deque()
    #print(d)
    cnt+=1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
H,W=map(int, input().split())
A=[]
d=deque()
for h in range(H):
  a=[]
  s=input()
  for w in range(W):
    if s[w]=='.':
      a.append(-1)
    else:
      a.append(0)
      d.append((h,w))
  A.append(a)
cnt=1
DIF=[(1,0),(0,1),(-1,0),(0,-1)]
tmp=deque()
while d:
  point=d.popleft()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      tmp.append((x,y))
      A[x][y]=cnt
  if not d:
    #print(tmp)
    d=copy.deepcopy(tmp)
    tmp=deque()
    #print(d)
    cnt+=1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

from collections import deque

q=deque([])
B=[[None]*H for _ in range (W)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

from collections import deque

q=deque([])
B=[[None]*H for _ in range (W)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
print(max([max(B[i]) for i in range(H)]))

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

import queue
q=queue.Queue()
B=[[None]*H for _ in range (W)]
cnt=0
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.put((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while q.empty()==False:
  XY=[]
  while q.empty()==False:
     XY.append(q.get())
  for xy in XY:
    for i in range(4):
      if 0<=xy[0]+dx[i]<=H-1 and 0<=xy[1]+dy[i]<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.put((xy[0]+dx[i],xy[1]+dy[i]))
print(max([max(B[i]) for i in range(H)]))

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

import queue
q=queue.Queue()
B=[[None]*H for _ in range (W)]
cnt=0
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.put((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while q.empty()==False:
  XY=[]
  while q.empty()==False:
     XY.append(q.get())
  for xy in XY:
    for i in range(4):
      if 0<=xy[0]+dx[i]<=H-1 and 0<=xy[1]+dy[i]<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.put((xy[0]+dx[i],xy[1]+dy[i]))
print(max([max(B[i]) for i in range(H)]))

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

import queue
q=queue.Queue()
B=[[0]*H for _ in range (W)]
cnt=0
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.put((i,j))
            B[i][j]=1
while sum([sum(B[k]) for k in range(H)])<H*W:
    new_q=[]
    while q.empty()==False:
        new_q.append(q.get())
    for t in new_q:
        if t[0]!=0:
            q.put((t[0]-1, t[1]))
            B[t[0]-1][t[1]]=1
        if t[0]!=H-1:
            q.put((t[0]+1, t[1]))
            B[t[0]+1][t[1]]=1
        if t[1]!=0:
            q.put((t[0], t[1]-1))
            B[t[0]][t[1]-1]=1
        if t[1]!=W-1:
            q.put((t[0], t[1]+1))
            B[t[0]][t[1]+1]=1
    cnt+=1
print(cnt)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy python submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

B=[[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            B[i][j]=1
import copy
cnt=0
C=copy.copy(B)
while sum([sum(C[k]) for k in range(W)])<H*W:
    B=copy.deepcopy(C)
    cnt+=1
    for i in range(H):
        for j in range(W):
            if B[i][j]==1:
                if i>0:
                    C[i-1][j]=1
                if i<H-1:
                    C[i+1][j]=1
                if j>0:
                    C[i][j-1]=1
                if j<H-1:
                    C[i][j+1]=1
print(cnt)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))