Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

stack=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j]:
            stack.append((i,j))


dh=[1,0,-1,0]
dw=[0,1,0,-1]

cnt=0
while stack:
    nstack=[]
    for h,w in stack:
        for k in range(4):
            th=h+dh[k]
            tw=w+dw[k]
            if not board[th][tw]:
                board[th][tw]=True
                nstack.append((th,tw))
    stack=nstack
    cnt+=1

print(cnt-1)

Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j]:
            q.append([i,j])

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append([h+1,w])
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append([h-1,w])
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append([h,w+1])
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append([h,w-1])

    q=nq
    cnt+=1

print(cnt-1)




Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j]:
            q.append([i,j])

cnt=0
while q:
    nq=[]
    for h,w in stack:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append([h+1,w])
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append([h-1,w])
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append([h,w+1])
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append([h,w-1])

    q=nq
    cnt+=1

print(cnt-1)




Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

stack=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j]:
            stack.append([i,j])

cnt=0
while stack:
    nstack=[]
    for h,w in stack:
        if not board[h+1][w]:
            board[h+1][w]=True
            nstack.append([h+1,w])
        if not board[h-1][w]:
            board[h-1][w]=True
            nstack.append([h-1,w])
        if not board[h][w+1]:
            board[h][w+1]=True
            nstack.append([h,w+1])
        if not board[h][w-1]:
            board[h][w-1]=True
            nstack.append([h,w-1])

    stack=nstack
    cnt+=1

print(cnt-1)

Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

stack=[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if board[i][j]:
            stack.append([i,j])


dh=[1,0,-1,0]
dw=[0,1,0,-1]

cnt=0
while stack:
    nstack=[]
    for h,w in stack:
        for k in range(4):
            th=h+dh[k]
            tw=w+dw[k]
            if not board[th][tw]:
                board[th][tw]=True
                nstack.append([th,tw])
    stack=nstack
    cnt+=1

print(cnt-1)




Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
H,W=map(int,input().split())

board=[list(input()) for _ in range(H)]
checked=[[-1 for _ in range(W)] for _ in range(H)]
dh=[1,0,-1,0]
dw=[0,-1,0,1]
ans=0

q=queue.Queue()

for i in range(H):
    for j in range(W):
        if board[i][j]=='#':
            checked[i][j]=0
            q.put([i,j])


while not q.empty():
    tmp=q.get()
    h,w=tmp[0],tmp[1]
    for i in range(4):
        th=h+dh[i]
        tw=w+dw[i]
        if 0<=th<H and 0<=tw<W and checked[th][tw]==-1:
            checked[th][tw]=checked[h][w]+1
            q.put([th,tw])
            ans=max(ans,checked[th][tw])
print(ans)


Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W=map(int,input().split())

board=[list(input()) for _ in range(H)]
checked=[[-1 for _ in range(W)] for _ in range(H)]
dh=[1,0,-1,0]
dw=[0,-1,0,1]
ans=0

q=deque([])

for i in range(H):
    for j in range(W):
        if board[i][j]=='#':
            checked[i][j]=0
            q.append([i,j])


while len(q)!=0:
    tmp=q.popleft()
    h,w=tmp[0],tmp[1]
    for i in range(4):
        th=h+dh[i]
        tw=w+dw[i]
        if 0<=th<H and 0<=tw<W and checked[th][tw]==-1:
            checked[th][tw]=checked[h][w]+1
            q.append([th,tw])
            ans=max(ans,checked[th][tw])
print(ans)


Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())

board=[list(input()) for _ in range(H)]
stack=list()
dh=[1,0,-1,0]
dw=[0,-1,0,1]


def boardcheck():
    nstack=list()
    global stack
    for dot in stack:
        for i in range(4):
            th=dot[0]+dh[i]
            tw=dot[1]+dw[i]
            if 0<=th<H and 0<=tw<W and board[th][tw]=='.':
                board[th][tw]='#'
                nstack.append([th,tw])
    return nstack


for i in range(H):
    for j in range(W):
        if board[i][j]=='#':
            stack.append([i,j])
count=0
while True:
    stack=boardcheck()
    if len(stack)==0:
        break
    count+=1

print(count)


Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())

board=[list(input()) for _ in range(H)]
stack=list()
dh=[1,0,-1,0]
dw=[0,-1,0,1]

for i in range(H):
    for j in range(W):
        if board[i][j]=='#':
            stack.append([i,j])

def boardcheck():
    nstack=list()
    global stack
    for dot in stack:
        for i in range(4):
            th=dot[0]+dh[i]
            tw=dot[1]+dw[i]
            if 0<=th<H and 0<=tw<W and board[th][tw]=='.':
                board[th][tw]='#'
                nstack.append([th,tw])
    stack=nstack[:]

count=0
while True:
    boardcheck()
    if len(stack)==0:
        break
    count+=1

print(count)


Fixed submission:
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)