Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import deque
  from array import array
  s,*c=open(0)
  h,w=map(int,s.split())
  f=array('h',[-1]*h*w)
  q=deque()
  for i,c in enumerate(''.join(t[:w]for t in c)):
    if c=='#':
      q.append(i)
      f[i]=0
  while q:
    i=q.popleft()
    v=f[i]+1
    j,k,l,m=i+w,i-w,i+1,i-1
    if h*w>j and f[j]<0:
      q.append(j)
      f[j]=v
    if k>=0 and f[k]<0:
      q.append(k)
      f[k]=v
    if w>i%w+1and f[l]<0:
      q.append(l)
      f[l]=v
    if i%w and f[m]<0:
      q.append(m)
      f[m]=v
  print(v-1)
if __name__=='__main__':
  main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  f=[-1]*h*w
  q=deque()
  for i,c in enumerate(''.join(t[:w]for t in c)):
    if c=='#':
      q.append(i)
      f[i]=0
  while q:
    i=q.popleft()
    v=f[i]+1
    j,k,l,m=i+w,i-w,i+1,i-1
    if h*w>j and f[j]<0:
      q.append(j)
      f[j]=v
    if k>=0 and f[k]<0:
      q.append(k)
      f[k]=v
    if w>i%w+1and f[l]<0:
      q.append(l)
      f[l]=v
    if i%w and f[m]<0:
      q.append(m)
      f[m]=v
  print(v-1)
if __name__=='__main__':
  main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[-1]*h*w
  q=deque()
  for i,d in enumerate(c):
    if d=='#':
      q.append(i)
      f[i]=0
  while q:
    y=q.popleft()
    v=f[y]
    if h*w>y+w and f[y+w]<0:
      q.append(y+w)
      f[y+w]=v+1
    if y>=w and f[y-w]<0:
      q.append(y-w)
      f[y-w]=v+1
    if w>y%w+1and f[y+1]<0:
      q.append(y+1)
      f[y+1]=v+1
    if y%w>0and f[y-1]<0:
      q.append(y-1)
      f[y-1]=v+1
  print(v)
if __name__=='__main__':
  main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[-1]*h*w
  q=deque()
  for i,d in enumerate(c):
    if d=='#':
      q.append(i)
      f[i]=0
  while q:
    y=q.popleft()
    v=f[y]
    y,x=divmod(y,w)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
      k=i*w+j
      if h>i>=0<=j<w and f[k]<0:
        f[k]=v+1
        q.append(k)
  print(v)
if __name__=='__main__':
  main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[-1]*h*w
  q=deque()
  for i in range(h*w):
    if c[i]=='#':
      q.append(i)
      f[i]=0
  while q:
    y=q.popleft()
    v=f[y]
    y,x=divmod(y,w)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
      k=i*w+j
      if h>i>=0<=j<w and'.'==c[k]*(f[k]<0):
        f[k]=v+1
        q.append(k)
  print(v)
if __name__=='__main__':
  main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[-1]*h*w
  q=deque()
  for i in range(h*w):
    if c[i]=='#':
      q.append((i//w,i%w))
      f[i]=0
  while q:
    y,x=q.popleft()
    v=f[y*w+x]
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
      k=i*w+j
      if h>i>=0<=j<w and'.'==c[k]*(f[k]<0):
        f[k]=v+1
        q.append((i,j))
  print(v)
if __name__=='__main__':
  main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[1]*h*w
  q=deque()
  for i in range(h*w):
    if c[i]=='#':
      q.append((i//w,i%w,0))
      f[i]=0
  while q:
    y,x,v=q.popleft()
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
      if h>i>=0<=j<w and'.'==c[i*w+j]*f[i*w+j]:
        f[i*w+j]=0
        q.append((i,j,v+1))
  print(v)
if __name__=='__main__':
  main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=[]
e=q.append
for i in range(h):
 for j in range(w):
  if'.'>c[i][j]:e((i,j,0))
a=0
while q:
 y,x,v=q.pop(0);a=max(a,v)
 for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
  if h>i>=0and w>j>=0and'#'<c[i][j]:c[i][j]='#';e((i,j,v+1))
print(a)

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=[]
for i in range(h):
 for j in range(w):
  if'.'>c[i][j]:q+=[(i,j,0)]
a=0
while q:
 y,x,v=q.pop(0);a=max(a,v)
 for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
  if h>i>=0and w>j>=0and'#'<c[i][j]:c[i][j]='#';q.append((i,j,v+1))
print(a)

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=[]
for i in range(h):
 for j in range(w):
  q+=[(i,j,0)]*(c[i][j]<'.')
a=0
while q:
 y,x,v=q.pop(0);a=max(a,v)
 for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
  if h>i>=0and w>j>=0and'#'<c[i][j]:c[i][j]='#';q+=[(i,j,v+1)]
print(a)

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import deque
    h,w=map(int,input().split())
    c=eval('list(input()),'*h)
    q=deque()
    for i in range(h):
        for j in range(w):
            if c[i][j]=='#':
                q.append((i,j,0))
    ans=0
    while q:
        y,x,v=q.popleft()
        ans=max(ans,v)
        for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
            if h>i>=0 and w>j>=0 and c[i][j]=='.':
                c[i][j]='#'
                q.append((i,j,v+1))
    print(ans)
if __name__=='__main__':
    main()

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)

Fixed submission:
from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)