Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
lis = set()
num = [[0] * w for i in range(h)]
s = [str(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            lis.add((i,j))
            num[i][j] = 1
cnt = -1
while lis != ():
    cnt += 1
    tmp = set()
    for x,y in lis:
        if x > 0:
            if num[x-1][y] == 0:
                num[x-1][y] = 1
                tmp.add((x-1,y))
        if x < h-1:
            if num[x+1][y] == 0:
                num[x+1][y] = 1
                tmp.add((x+1,y))
        if y > 0:
            if num[x][y-1] == 0:
                num[x][y-1] = 1
                tmp.add((x,y-1))
        if y < w-1:
            if num[x][y+1] == 0:
                num[x][y+1] = 1
                tmp.add((x,y+1))
    lis = tmp
print(cnt)

Fixed submission:
import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]

  black = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])

  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not M[bi - 1][bj]:
        M[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not M[bi][bj - 1]:
        M[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not M[bi + 1][bj]:
        M[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not M[bi][bj + 1]:
        M[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
lis = []
num = [[0] * w for i in range(h)]
s = [str(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            lis.append([i,j])
            num[i][j] = 1
cnt = -1
while lis != []:
    cnt += 1
    tmp = []
    for x,y in lis:
        if x > 0:
            if num[x-1][y] == 0:
                num[x-1][y] = 1
                tmp.append([x-1,y])
        if x < h-1:
            if num[x+1][y] == 0:
                num[x+1][y] = 1
                tmp.append([x+1,y])
        if y > 0:
            if num[x][y-1] == 0:
                num[x][y-1] = 1
                tmp.append([x,y-1])
        if y < w-1:
            if num[x][y+1] == 0:
                num[x][y+1] = 1
                tmp.append([x,y+1])
    lis = tmp
print(cnt)

Fixed submission:
import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]

  black = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])

  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not M[bi - 1][bj]:
        M[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not M[bi][bj - 1]:
        M[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not M[bi + 1][bj]:
        M[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not M[bi][bj + 1]:
        M[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
lis = []
s = [str(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            lis.append([i, j])
ans = 0
for i in range(h):
    for j in range(w):
        num = 10 ** 7
        for x, y in lis:
            num = min(num, abs(i - x) + abs(j - y))
        ans = max(ans, num)
print(ans)


Fixed submission:
import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]

  black = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])

  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not M[bi - 1][bj]:
        M[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not M[bi][bj - 1]:
        M[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not M[bi + 1][bj]:
        M[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not M[bi][bj + 1]:
        M[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
lis = []
s = [str(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            lis.append([i, j])
ans = 0
for i in range(h):
    for j in range(w):
        num = 10 ** 7
        for x, y in lis:
            num = min(num, abs(i - x) + abs(j - y))
        ans = max(ans, num)
print(ans)


Fixed submission:
import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]

  black = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])

  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not M[bi - 1][bj]:
        M[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not M[bi][bj - 1]:
        M[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not M[bi + 1][bj]:
        M[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not M[bi][bj + 1]:
        M[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Runtime Error):
n,w = map(int,input().split())
lis = []
s = [str(input()) for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      lis.append([i,j])
ans = 0
for i in range(h):
  for j in range(w):
    num = 10 ** 7
    for x,y in lis:
      num = min(num,abs(i-x)+abs(j-y))
    ans = max(ans,num)
print(ans)
      

Fixed submission:
import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]

  black = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])

  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not M[bi - 1][bj]:
        M[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not M[bi][bj - 1]:
        M[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not M[bi + 1][bj]:
        M[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not M[bi][bj + 1]:
        M[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()