Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[float("inf")]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())

Fixed submission:
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[-1]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==-1:
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[float("inf")]*w for i in range(h)]
    que=deque([])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())




Fixed submission:
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[-1]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==-1:
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())

Buggy python submission (verdict: Runtime Error):
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[float("inf")]*w for i in range(h)]
    que=deque([])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    while que:
        p=que.popleft()
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
                d[nx][ny]=d[p[0]][p[1]]+1
                que.append((nx,ny))  
    ans=0
    for i in range(h):
        ans=max(ans,d[i])
    return ans
if __name__=='__main__':
    print(main())




Fixed submission:
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[-1]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==-1:
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())

Buggy python submission (verdict: Runtime Error):
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[float("inf")]*w for i in range(h)]
    que=deque([])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    while que:
        p=que.popleft()
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
                d[nx][ny]=d[p[0]][p[1]]+1
                que.append((nx,ny))  
    ans=0
    for i in range(h):
        ans=max(ans,d[i])
if __name__=='__main__':
    print(main())




Fixed submission:
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[-1]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==-1:
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())