Buggy python submission (verdict: Runtime Error):
import numpy as np

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

data = np.zeros((3*h,3*w),dtype=np.int)
datamap = np.ones((3*h,3*w),dtype=np.int)

datamaplt = np.ones((3*h,3*w),dtype=np.int)
datamaplt = datamaplt*(10)
datamaprt = np.ones((3*h,3*w),dtype=np.int)
datamaprt = datamaprt*(10)
datamaplb = np.ones((3*h,3*w),dtype=np.int)
datamaplb = datamaplb*(10)
datamaprb = np.ones((3*h,3*w),dtype=np.int)
datamaprb = datamaprb*(10)

for i in range(h):
    for  j in range(w):
        if data_t[i][j] == "#":
            data[h+i,w+j] = 1
        datamaplt[h+i,w+j] = 0
        datamaprt[h+i,w+j] = 0
        datamaplb[h+i,w+j] = 0
        datamaprb[h+i,w+j] = 0
        

for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            fromtop = datamaplt[ii-1,jj]+1
            fromleft = datamaplt[ii,jj-1]+1
            datamaplt[ii,jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            fromtop = datamaprt[ii-1,jj]+1
            fromright = datamaprt[ii,jj+1]+1
            datamaprt[ii,jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            frombottom = datamaplb[ii+1,jj]+1
            fromleft = datamaplb[ii,jj-1]+1
            datamaplb[ii,jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            frombottom = datamaprb[ii+1,jj]+1
            fromright = datamaprb[ii,jj+1]+1
            datamaprb[ii,jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj]) > ans:
            ans =  min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj])
            
print(ans)


Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))

for i in range(h):
    #data.append([])
    #data[i+1].append(10**9)
    data.append(list(dummylist0))
    
    datamaplt.append(list(dummylist0))
    datamaprt.append(list(dummylist0))
    datamaplb.append(list(dummylist0))
    datamaprb.append(list(dummylist0))
    
    """for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)"""
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i][j+1] = 1

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflt_fromleft = 10**9
                
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = beflt_fromleft+1
            
            min_ = min(fromtop,fromleft)
            datamaplt[ii][jj] = min_
            beflt_fromleft = min_
        else:
            beflt_fromleft = 0
            

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrt_fromright = 10**9
            fromtop = datamaprt[ii-1][jj]+1
            fromright = befrt_fromright+1
            
            min_ = min(fromtop,fromright)
            datamaprt[ii][jj] = min_
            befrt_fromright = min_
        else:
            befrt_fromright = 0

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflb_fromleft = 10**9
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = beflb_fromleft+1
            min_ = min(frombottom,fromleft)
            datamaplb[ii][jj] = min_
            beflb_fromleft = min_
        else:
            beflb_fromleft = 0

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrb_fromright= 10**9
            frombottom = datamaprb[ii+1][jj]+1
            fromright = befrb_fromright+1
            min_= min(fromright,frombottom)
            datamaprb[ii][jj] = min_
        else:
            befrb_fromright= 0
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)


Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(dummylist )
datamaplt.append(dummylist )
datamaprt.append(dummylist )
datamaplb.append(dummylist )
datamaprb.append(dummylist )

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    
    datamaplt.append(list(dummylist0) )
    datamaprt.append(list(dummylist0 ))
    datamaplb.append(list(dummylist0 ))
    datamaprb.append(list(dummylist0 ))
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)

data.append(dummylist )
datamaplt.append(dummylist )
datamaprt.append(dummylist )
datamaplb.append(dummylist )
datamaprb.append(dummylist )
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)


Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)
    
data.append(dummylist )
datamaplt.append(dummylist )
datamaprt.append(dummylist )
datamaplb.append(dummylist )
datamaprb.append(dummylist )

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append(dummylist )
datamaplt.append(dummylist )
datamaprt.append(dummylist )
datamaplb.append(dummylist )
datamaprb.append(dummylist )

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)


Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)


Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

data = np.zeros((2+h,2+w),dtype=np.int)
datamap = np.ones((2+h,2+w),dtype=np.int)

datamaplt = np.ones((2+h,2+w),dtype=np.int)
datamaplt = datamaplt*(10**9)
datamaprt = np.ones((2+h,2+w),dtype=np.int)
datamaprt = datamaprt*(10**9)
datamaplb = np.ones((2+h,2+w),dtype=np.int)
datamaplb = datamaplb*(10**9)
datamaprb = np.ones((2+h,2+w),dtype=np.int)
datamaprb = datamaprb*(10**9)

for i in range(h):
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i,1+j] = 1
        datamaplt[1+i,1+j] = 0
        datamaprt[1+i,1+j] = 0
        datamaplb[1+i,1+j] = 0
        datamaprb[1+i,1+j] = 0
        

for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii,jj] == 0:
            fromtop = datamaplt[ii-1,jj]+1
            fromleft = datamaplt[ii,jj-1]+1
            datamaplt[ii,jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii,jj] == 0:
            fromtop = datamaprt[ii-1,jj]+1
            fromright = datamaprt[ii,jj+1]+1
            datamaprt[ii,jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii,jj] == 0:
            frombottom = datamaplb[ii+1,jj]+1
            fromleft = datamaplb[ii,jj-1]+1
            datamaplb[ii,jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii,jj] == 0:
            frombottom = datamaprb[ii+1,jj]+1
            fromright = datamaprb[ii,jj+1]+1
            datamaprb[ii,jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj]) > ans:
            ans =  min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj])
            
print(ans)


Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

data = np.zeros((3*h,3*w),dtype=np.int)
datamap = np.ones((3*h,3*w),dtype=np.int)

datamaplt = np.ones((3*h,3*w),dtype=np.int)
datamaplt = datamaplt*(10)
datamaprt = np.ones((3*h,3*w),dtype=np.int)
datamaprt = datamaprt*(10)
datamaplb = np.ones((3*h,3*w),dtype=np.int)
datamaplb = datamaplb*(10)
datamaprb = np.ones((3*h,3*w),dtype=np.int)
datamaprb = datamaprb*(10)

for i in range(h):
    for  j in range(w):
        if data_t[i][j] == "#":
            data[h+i,w+j] = 1
        datamaplt[h+i,w+j] = 0
        datamaprt[h+i,w+j] = 0
        datamaplb[h+i,w+j] = 0
        datamaprb[h+i,w+j] = 0
        

for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            fromtop = datamaplt[ii-1,jj]+1
            fromleft = datamaplt[ii,jj-1]+1
            datamaplt[ii,jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            fromtop = datamaprt[ii-1,jj]+1
            fromright = datamaprt[ii,jj+1]+1
            datamaprt[ii,jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            frombottom = datamaplb[ii+1,jj]+1
            fromleft = datamaplb[ii,jj-1]+1
            datamaplb[ii,jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            frombottom = datamaprb[ii+1,jj]+1
            fromright = datamaprb[ii,jj+1]+1
            datamaprb[ii,jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj]) > ans:
            ans =  min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj])
            
print(ans)

Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

data = np.zeros((3*h,3*w),dtype=np.int)
datamap = np.ones((3*h,3*w),dtype=np.int)

datamaplt = np.ones((3*h,3*w),dtype=np.int)
datamaplt = datamaplt*(10)
datamaprt = np.ones((3*h,3*w),dtype=np.int)
datamaprt = datamaprt*(10)
datamaplb = np.ones((3*h,3*w),dtype=np.int)
datamaplb = datamaplb*(10)
datamaprb = np.ones((3*h,3*w),dtype=np.int)
datamaprb = datamaprb*(10)
for i in range(h):
    for  j in range(w):
        if data_t[i][j] == "#":
            data[h+i,w+j] = 1
        datamaplt[h+i,w+j] = 0
        datamaprt[h+i,w+j] = 0
        datamaplb[h+i,w+j] = 0
        datamaprb[h+i,w+j] = 0
        

for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            fromtop = datamaplt[ii-1,jj]+1
            fromleft = datamaplt[ii,jj-1]+1
            datamaplt[ii,jj] = min(fromtop,fromleft)

for i in range(h):
    for  j in range(w-1,-1,-1):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            fromtop = datamaprt[ii-1,jj]+1
            fromright = datamaprt[ii,jj+1]+1
            datamaprt[ii,jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            frombottom = datamaplb[ii+1,jj]+1
            fromleft = datamaplb[ii,jj-1]+1
            datamaplb[ii,jj] = min(frombottom,fromleft)
            
for i in range(h-1,-1,-1):
    for  j in range(w-1,-1,-1):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            frombottom = datamaprb[ii+1,jj]+1
            fromright = datamaprb[ii,jj+1]+1
            datamaprb[ii,jj] = min(fromright,frombottom)
            
for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        datamap[ii,jj] = min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj])
        
ans = 0             
for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if datamap[ii,jj] > ans:
            ans = datamap[ii,jj]
            
print(ans)

Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

data = np.zeros((3*h,3*w),dtype=np.int)
datamap = np.ones((3*h,3*w),dtype=np.int)
datamap = datamap*(10)
for i in range(h):
    for  j in range(w):
        if data_t[i][j] == "#":
            data[h+i,w+j] = 1
        datamap[h+i,w+j] = 0
        

for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if data[ii,jj] == 0:
            step = 0
            ditect = False
            fromtop = datamap[ii-1,jj]+1
            fromleft = datamap[ii,jj-1]+1
            if (fromtop>1)&(fromleft>1):
                searchdep = min(fromtop,fromleft,h-i+w-j-2)
                #print(i,j,searchdep)
                ditect = False 
                for step in range(1,searchdep+1):
                    for jjj in range(step+1):
                        if data[ii+(step-jjj),jj+jjj]==1:
                            ditect = True
                            break
                    if ditect == True:
                        break
                if ditect == False:
                    step = 10**9
                    
                datamap[ii,jj] = min(fromtop,fromleft,step)  
            else:
                datamap[ii,jj] = min(fromtop,fromleft)
            
ans = 0             
for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        if datamap[ii,jj] > ans:
            ans = datamap[ii,jj]
            
print(ans)

Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

data = np.zeros((h,w),dtype=np.int)
countw = 0
for i in range(h):
    for  j in range(w):
        if data_t[i][j] == "#":
            data[i,j] = 1
        if data_t[i][j] ==".":
            countw += 1 

if countw >0:
    allpainted = False
else:
    allpainted = True

count = 0  
while(allpainted == False):
    countw = 0
    data_temp = data.copy()
    for i in range(h):
        for  j in range(w):
            t = data[i,j]
            if t == 0:
                around = False
                if (i>0):
                    if data[i-1,j]==1:
                        around = True
                if (around == False)&(i<h-1):
                    if data[i+1,j]==1:
                        around = True
                if (around == False)&(j>0):
                    if data[i,j-1]==1:
                        around = True
                if (around == False)&(j<w-1):
                    if data[i,j+1]==1:
                        around = True
                
                if around == True:
                    data_temp[i,j] = 1
                else:
                    data_temp[i,j] = 0
                    countw += 1
            
            else:
                data_temp[i,j] = 1
            
    
    if countw == 0:
        allpainted = True
    
    data = data_temp.copy()
    count += 1

print(count)

Fixed submission:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)