Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def bfs():
    d = [[[float("inf")] * w for _ in range(h)] for _ in range(len(kabe))]
    ans = float("inf")
    for i in range(len(kabe)):
        que = deque([])
        que.append((kabe[i][0], kabe[i][1]))
        d[i][kabe[i][0]][kabe[i][1]] = 0
        while que:
            x, y = que.popleft()
            for dx, dy in ([1, 0], [0, 1], [0, -1], [-1, 0]):
                nx = x + dx
                ny = y + dy
                if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[i][nx][ny] == float("inf"):
                    que.append((nx, ny))
                    d[i][nx][ny] = d[i][x][y] + 1
    li = []
    for i in range(h):
        for j in range(w):
            tmp = [d[k][i][j] for k in range(len(kabe))]
            li.append(min(tmp))
    return max(li)

h, w = na()
maze = [list(input()) for _ in range(h)]
kabe = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            kabe.append((i, j))
print(bfs())



Fixed submission:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def bfs():
    d = [[[float("inf")] * w for _ in range(h)] for _ in range(len(kabe))]
    ans = float("inf")
    for i in range(len(kabe)):
        que = deque([])
        que.append((kabe[i][0], kabe[i][1]))
        d[i][kabe[i][0]][kabe[i][1]] = 0
        while que:
            x, y = que.popleft()
            for dx, dy in ([1, 0], [0, 1], [0, -1], [-1, 0]):
                nx = x + dx
                ny = y + dy
                if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[i][nx][ny] == float("inf"):
                    que.append((nx, ny))
                    d[i][nx][ny] = d[i][x][y] + 1
    li = []
    for i in range(h):
        for j in range(w):
            tmp = [d[k][i][j] for k in range(len(kabe))]
            li.append(min(tmp))
    return max(li)

h, w = na()
maze = [list(input()) for _ in range(h)]
kabe = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            kabe.append((i, j))
print(bfs())


Fixed submission:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

h, w = na()
a = [list(input()) for i in range(h)]
ct = 0
ds = h * w
trial = 0
pli = []
lens = [[2001 for i in range(w)] for j in range(h)]
for x in range(w):
    for y in range(h):
        if a[x][y] == '#':
            pli.append([x, y])
            lens[x][y] = 0
for y in range(h):
    for x in range(w):
        if [x, y] not in pli:
            for p in pli:
                tmp = abs(x - p[0]) + abs(y - p[1])
                if lens[x][y] > tmp:
                    lens[x][y] = tmp
print(np.max(lens))

Fixed submission:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

h, w = na()
a = [list(input()) for i in range(h)]
ct = 0
ds = h * w
trial = 0
pli = []
lens = [[2001 for i in range(w)] for j in range(h)]
for x in range(w):
    for y in range(h):
        if a[x][y] == '#':
            pli.append([x, y])
            lens[x][y] = 0
for y in range(h):
    for x in range(w):
        if [x, y] not in pli:
            for p in pli:
                tmp = abs(x - p[0]) + abs(y - p[1])
                if lens[x][y] > tmp:
                    lens[x][y] = tmp
print(np.max(lens))

Fixed submission:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)

Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

def change(a, x, y, h, w):
    ct = 0
    if x > 0:
        if a[x - 1][y] == '.':
            a[x - 1][y] = '#'
            ct += 1
    if y > 0:
        if a[x][y - 1] == '.':
            a[x][y - 1] = '#'
            ct += 1
    if x < w - 1:
        if a[x + 1][y] == '.':
            a[x + 1][y] = '#'
            ct += 1
    if y < h - 1:
        if a[x][y + 1] == '.':
            a[x][y + 1] = '#'
            ct += 1
    return ct


h, w = na()
a = [list(input()) for i in range(h)]
ct = 0
ds = h * w
trial = 0
for y in range(h):
    for x in range(w):
        if a[x][y] == '#':
            ct += 1
#print(ct)
while ct != ds:
    li = []
    for y in range(h):
        for x in range(w):
            if a[x][y] == '#':
                li.append([x, y])
    for p in li:
        ct += change(a, p[0], p[1], h, w)
    #print(ct)
    trial += 1

print(trial)




Fixed submission:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)

Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

def change(a, x, y, h, w):
    ct = 0
    if x > 0:
        if a[x - 1][y] == '.':
            a[x - 1][y] = '#'
            ct += 1
    if y > 0:
        if a[x][y - 1] == '.':
            a[x][y - 1] = '#'
            ct += 1
    if x < w - 1:
        if a[x + 1][y] == '.':
            a[x + 1][y] = '#'
            ct += 1
    if y < h - 1:
        if a[x][y + 1] == '.':
            a[x][y + 1] = '#'
            ct += 1
    return ct


h, w = na()
a = [list(input()) for i in range(h)]
ct = 0
ds = h * w
trial = 0
for y in range(h):
    for x in range(w):
        if a[x][y] == '#':
            ct += 1

while ct != ds:
    li = []
    for y in range(h):
        for x in range(w):
            if a[x][y] == '#':
                li.append([x, y])
    for p in li:
        ct += change(a, p[0], p[1], h, w)
    trial += 1

print(trial)



Fixed submission:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)

Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

def change(a, x, y, h, w):
    ct = 0
    if x > 0:
        if a[x - 1][y] == '.':
            a[x - 1][y] = '#'
            ct += 1
    if y > 0:
        if a[x][y - 1] == '.':
            a[x][y - 1] = '#'
            ct += 1
    if x < w - 1:
        if a[x + 1][y] == '.':
            a[x + 1][y] = '#'
            ct += 1
    if y < h - 1:
        if a[x][y + 1] == '.':
            a[x][y + 1] = '#'
            ct += 1
    return ct


h, w = na()
a = [list(input()) for i in range(h)]
ct = 0
ds = h * w
trial = 0
for y in range(h):
    for x in range(w):
        if a[x][y] == '#':
            ct += 1

while ct != ds:
    li = []
    for y in range(h):
        for x in range(w):
            if a[x][y] == '#':
                li.append([x, y])
    for p in li:
        ct += change(a, p[0], p[1], h, w)
    trial += 1

print(trial)



Fixed submission:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)