Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())

grid = [None] * H
dist = [[2000] * W for i in range(H)]
from collections import deque
q = deque([])
for i in range(H):
  grid[i] = readline().rstrip()
  for j in range(len(grid[i])):
    if grid[i][j] == "#":
      q.append((i,j,0))

cases = ((0,1),(0,-1),(1,0),(-1,0))
ans = 0
seen = set()
while q:
  y,x,d = q.popleft()
  if dist[y][x] <= d:
    continue
  dist[y][x] = d
  seen.add((y,x))
  if ans < d:
    ans = d
  for c in cases:
    if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
      if (y + c[0],x + c[1]) in seen:
        continue
      q.append((y + c[0],x + c[1],d + 1))
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())

grid = [None] * H
dist = [[2000] * W for i in range(H)]
from collections import deque
q = deque([])
for i in range(H):
  grid[i] = readline().rstrip()
  for j in range(len(grid[i])):
    if grid[i][j] == "#":
      q.append((i,j,0))

cases = ((0,1),(0,-1),(1,0),(-1,0))
ans = 0
seen = set()
while q:
  y,x,d = q.popleft()
  if dist[y][x] <= d:
    continue
  dist[y][x] = d
  seen.add((y,x))
  if ans < d:
    ans = d
  for c in cases:
    if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
      if (y + c[0],x + c[1]) in seen:
        continue
      q.append((y + c[0],x + c[1],d + 1))
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())

grid = [None] * H
dist = [[2000] * W for i in range(H)]
from collections import deque
q = deque([])
for i in range(H):
  grid[i] = readline().rstrip()
  for j in range(len(grid[i])):
    if grid[i][j] == "#":
      q.append((i,j,0))

cases = ((0,1),(0,-1),(1,0),(-1,0))
ans = 0
while q:
  y,x,d = q.popleft()
  if dist[y][x] <= d:
    continue
  dist[y][x] = d
  if ans < d:
    ans = d
  for c in cases:
    if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
      q.append((y + c[0],x + c[1],d + 1))
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())

grid = [None] * H
dist = [[2000] * W for i in range(H)]
from collections import deque
q = deque([])
for i in range(H):
  grid[i] = readline().rstrip()
  for j in range(len(grid[i])):
    if grid[i][j] == "#":
      q.append((i,j,0))

cases = ((0,1),(0,-1),(1,0),(-1,0))
ans = 0
while q:
  y,x,d = q.popleft()
  if dist[y][x] <= d:
    continue
  dist[y][x] = d
  if ans < d:
    ans = d
  for c in cases:
    if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
      q.append((y + c[0],x + c[1],d + 1))
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
INF=10**4
a=[[INF for j in range(W)] for i in range(H)]
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i][j]=0

for i in range(H):
  for j in range(0,W-1):
    if a[i][j+1]>a[i][j]+1:
      a[i][j+1]=a[i][j]+1
for i in range(H-1,-1,-1):
  for j in range(W-1,0,-1):
    if a[i][j-1]>a[i][j]+1:
      a[i][j-1]=a[i][j]+1

for j in range(W):
  for i in range(0,H-1):
    if a[i+1][j]>a[i][j]+1:
      a[i+1][j]=a[i][j]+1
for j in range(W-1,-1,-1):
  for i in range(H-1,0,-1):
    if a[i-1][j]>a[i][j]+1:
      a[i-1][j]=a[i][j]+1

ans=0
for i in range(H):
  ans=max(ans,max(a[i]))
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
starts=[]
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0
      starts.append([i,j])

while starts:
  node=starts.pop()
  y=node[0]
  x=node[1]
  for i in range(x,W-1):
    np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
  for i in range(x,0,-1):
    np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
  for j in range(y,H-1):
    np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
  for j in range(y,0,-1):
    np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
INF=10**4
nums=[[INF for i in range(W)] for j in range(H)]
starts=[]
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      starts.append([i,j,0])

while starts:
  node=starts.pop()
  y=node[0]
  x=node[1]
  p=node[2]
  if nums[y][x]<=p:
    continue
  for i in range(x,W):
    if nums[y][i]>i-x+p:
      nums[y][i]=i-x+p
    else:
      break
  for i in range(x-1,-1,-1):
    if nums[y][i]>x-i+p:
      nums[y][i]=x-i+p
    else:
      break
  if y-1>=0:
    starts.append([y-1,x,p+1])
  if y+1<H:
    starts.append([y+1,x,p+1])

ans=0
for i in range(H):
  ans=max(max(nums[i]),ans)
  
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
INF=10**4
nums=[[INF for i in range(W)] for j in range(H)]
starts=[]
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      starts.append([i,j,0])

while starts:
  node=starts.pop()
  y=node[0]
  x=node[1]
  p=node[2]
  if nums[y][x]<=p:
    continue
  for i in range(x,W):
    if nums[y][i]>i-x+p:
      nums[y][i]=i-x+p
    else:
      break
  for i in range(x-1,-1,-1):
    if nums[y][i]>x-i+p:
      nums[y][i]=x-i+p
    else:
      break
  for j in range(y+1,H):
    if nums[j][x]>j-y+p:
      nums[j][x]=j-y+p
    else:
      break
  for j in range(y-1,-1,-1):
    if nums[j][x]>y-j+p:
      nums[j][x]=y-j+p
    else:
      break
  if y-1>=0 and x-1>=0:
    starts.append([y-1,x-1,p+2])
  if y+1<H and x+1<W:
    starts.append([y+1,x+1,p+2])
  if y-1>=0 and x+1<W:
    starts.append([y-1,x+1,p+2])
  if y+1<H and x-1>=0:
    starts.append([y+1,x-1,p+2])

ans=0
for i in range(H):
  ans=max(max(nums[i]),ans)
  
print(ans)
  
  

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def solve():
  h,w=map(int,input().split())
  grid=[None]*h
  seen=[[-1 for i in range(w)] for j in range(h)]
  
  que=deque()
  for i in range(h):
    grid[i]=list(input())
    for j in range(len(grid[i])):
      if grid[i][j]=="#":
        grid[i][j]="."
        que.append([i,j,0])
        
  ans=0
  while que:
    node=que.popleft()
    y=node[0]
    x=node[1]
    p=node[2]
    if grid[y][x]=="#":
      continue
    if grid[y][x]==".":
      grid[y][x]="#"
    if y-1>=0:
      que.append([y-1,x,p+1])
    if y+1<h:
      que.append([y+1,x,p+1])
    if x-1>=0:
      que.append([y,x-1,p+1])
    if x+1<w:
      que.append([y,x+1,p+1])
  print(max(p-1,0))

solve()

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=list(input())
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      grid[i][j]="."
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if grid[y][x]=="#":
    continue
  if grid[y][x]==".":
    grid[y][x]="#"
  if y-1>=0:
    que.append([y-1,x,p+1])
  if y+1<h:
    que.append([y+1,x,p+1])
  if x-1>=0:
    que.append([y,x-1,p+1])
  if x+1<w:
    que.append([y,x+1,p+1])
print(max(p-1,0))

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=list(input())
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      grid[i][j]="."
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if grid[y][x]=="#":
    continue
  if grid[y][x]==".":
    grid[y][x]="#"
  ans=max(ans,p)
  if y-1>=0:
    que.append([y-1,x,p+1])
  if y+1<h:
    que.append([y+1,x,p+1])
  if x-1>=0:
    que.append([y,x-1,p+1])
  if x+1<w:
    que.append([y,x+1,p+1])
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
grid=None
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  else:
    continue
  if y-1>=0:
    que.append([y-1,x,p+1])
  if y+1<h:
    que.append([y+1,x,p+1])
  if x-1>=0:
    que.append([y,x-1,p+1])
  if x+1<w:
    que.append([y,x+1,p+1])
print(max(p-1,0))

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
grid=None
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  else:
    continue
  ans=p
  if y-1>=0 and seen[y-1][x]==-1:
    que.append([y-1,x,p+1])
  if y+1<h and seen[y+1][x]==-1:
    que.append([y+1,x,p+1])
  if x-1>=0 and seen[y][x-1]==-1:
    que.append([y,x-1,p+1])
  if x+1<w and seen[y][x+1]==-1:
    que.append([y,x+1,p+1])
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  else:
    continue
  ans=p
  if y-1>=0 and seen[y-1][x]==-1:
    que.append([y-1,x,p+1])
  if y+1<h and seen[y+1][x]==-1:
    que.append([y+1,x,p+1])
  if x-1>=0 and seen[y][x-1]==-1:
    que.append([y,x-1,p+1])
  if x+1<w and seen[y][x+1]==-1:
    que.append([y,x+1,p+1])
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  else:
    continue
  ans=p
  if y-1>=0 and seen[y-1][x]==-1:
    que.append([y-1,x,p+1])
  if y+1<h and seen[y+1][x]==-1:
    que.append([y+1,x,p+1])
  if x-1>=0 and seen[y][x-1]==-1:
    que.append([y,x-1,p+1])
  if x+1<w and seen[y][x+1]==-1:
    que.append([y,x+1,p+1])
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  elif seen[y][x]<=p:
    continue
  else:
    seen[y][x]=p
  ans=p
  if y-1>=0 and seen[y-1][x]==-1:
    que.append([y-1,x,p+1])
  if y+1<h and seen[y+1][x]==-1:
    que.append([y+1,x,p+1])
  if x-1>=0 and seen[y][x-1]==-1:
    que.append([y,x-1,p+1])
  if x+1<w and seen[y][x+1]==-1:
    que.append([y,x+1,p+1])
print(ans)
    
    

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  elif seen[y][x]<=p:
    continue
  else:
    seen[y][x]=p
  ans=p
  if y-1>=0 and seen[y-1][x]==-1:
    que.append([y-1,x,p+1])
  if y+1<h and seen[y+1][x]==-1:
    que.append([y+1,x,p+1])
  if x-1>=0 and seen[y][x-1]==-1:
    que.append([y,x-1,p+1])
  if x+1<w and seen[y][x+1]==-1:
    que.append([y,x+1,p+1])
print(ans)
    
    

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  elif seen[y][x]<=p:
    continue
  else:
    seen[y][x]=p
  ans=p
  if y-1>=0:
    que.append([y-1,x,p+1])
  if y+1<h:
    que.append([y+1,x,p+1])
  if x-1>=0:
    que.append([y,x-1,p+1])
  if x+1<w:
    que.append([y,x+1,p+1])
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
seen=[[-1 for i in range(w)] for j in range(h)]
from collections import deque
que=deque()
for i in range(h):
  grid[i]=input()
  for j in range(len(grid[i])):
    if grid[i][j]=="#":
      que.append([i,j,0])
      
ans=0
while que:
  node=que.popleft()
  y=node[0]
  x=node[1]
  p=node[2]
  if seen[y][x]==-1:
    seen[y][x]=p
  elif seen[y][x]<=p:
    continue
  else:
    seen[y][x]=p
  ans=max(ans,p)
  if y-1>=0:
    que.append([y-1,x,p+1])
  if y+1<h:
    que.append([y+1,x,p+1])
  if x-1>=0:
    que.append([y,x-1,p+1])
  if x+1<w:
    que.append([y,x+1,p+1])
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
INF=10**6
from collections import deque
stack=deque()
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.popleft()
  y=v[0]
  x=v[1]
  p=v[2]
  grid[y][x]=p
  if y-1>=0 and p+1<grid[y-1][x]:
    stack.append([y-1,x,p+1])
  if y+1<h and p+1<grid[y+1][x]:
    stack.append([y+1,x,p+1])
  if x-1>=0 and p+1<grid[y][x-1]:
    stack.append([y,x-1,p+1])
  if x+1<w and p+1<grid[y][x+1]:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
INF=10**6
stack=[]
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.pop()
  y=v[0]
  x=v[1]
  p=v[2]
  grid[y][x]=p
  if y-1>=0 and p+1<grid[y-1][x]:
    stack.append([y-1,x,p+1])
  if y+1<h and p+1<grid[y+1][x]:
    stack.append([y+1,x,p+1])
  if x-1>=0 and p+1<grid[y][x-1]:
    stack.append([y,x-1,p+1])
  if x+1<w and p+1<grid[y][x+1]:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
INF=10**6
stack=[]
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.pop()
  y=v[0]
  x=v[1]
  p=v[2]
  grid[y][x]=p
  if y-1>=0 and p+1<grid[y-1][x]:
    stack.append([y-1,x,p+1])
  if y+1<h and p+1<grid[y+1][x]:
    stack.append([y+1,x,p+1])
  if x-1>=0 and p+1<grid[y][x-1]:
    stack.append([y,x-1,p+1])
  if x+1<w and p+1<grid[y][x+1]:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
INF=10**6
stack=[]
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.pop()
  y=v[0]
  x=v[1]
  p=v[2]
  if p<grid[y][x]:
    grid[y][x]=p
  else:
    continue
  if y-1>=0:
    stack.append([y-1,x,p+1])
  if y+1<h:
    stack.append([y+1,x,p+1])
  if x-1>=0:
    stack.append([y,x-1,p+1])
  if x+1<w:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[None]*h
INF=10**6
stack=[]
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.pop()
  y=v[0]
  x=v[1]
  p=v[2]
  if p<grid[y][x]:
    grid[y][x]=p
  else:
    continue
  if y-1>=0:
    stack.append([y-1,x,p+1])
  if y+1<h:
    stack.append([y+1,x,p+1])
  if x-1>=0:
    stack.append([y,x-1,p+1])
  if x+1<w:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)


Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input())
grid=[None]*h
INF=10**6
stack=[]
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.pop()
  y=v[0]
  x=v[1]
  p=v[2]
  if p<grid[y][x]:
    grid[y][x]=p
  else:
    continue
  if y-1>=0:
    stack.append([y-1,x,p+1])
  if y+1<h:
    stack.append([y+1,x,p+1])
  if x-1>=0:
    stack.append([y,x-1,p+1])
  if x+1<w:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())