Buggy python submission (verdict: Time Limit Exceeded):
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


from collections import deque

update_q = deque((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

pass
from copy import copy
def update(ary, update_q):
    for _ in range(len(update_q)):
        pos = update_q.popleft()
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
    return ary, update_q


black_count = len(update_q)
while black_count < w * h:
    ary, update_q = update(ary, update_q)
    black_count += len(update_q)


print(max(elem for line in ary for elem in line))


Fixed submission:
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


from collections import deque

update_q = deque((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

def update(ary, update_q):
    for _ in range(len(update_q)):
        pos = update_q.popleft()
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
    return ary, update_q


black_count = len(update_q)
update_count = 0
while black_count < w * h:
    ary, update_q = update(ary, update_q)
    black_count += len(update_q)
    update_count += 1


print(update_count)

Buggy python submission (verdict: Time Limit Exceeded):
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


update_list = set((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

from copy import copy
def update(ary, update_list):
    for pos in copy(update_list):
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_list.add((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_list.add((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_list.add((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_list.add((uy, ux))
        update_list.remove((y, x))
    return ary, update_list


black_count = len(update_list)
while black_count < w * h:
    ary, update_list = update(ary, update_list)
    black_count += len(update_list)


print(max(elem for line in ary for elem in line))


Fixed submission:
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


from collections import deque

update_q = deque((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

def update(ary, update_q):
    for _ in range(len(update_q)):
        pos = update_q.popleft()
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
    return ary, update_q


black_count = len(update_q)
update_count = 0
while black_count < w * h:
    ary, update_q = update(ary, update_q)
    black_count += len(update_q)
    update_count += 1


print(update_count)

Buggy python submission (verdict: Runtime Error):
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    line = input()
    ary.append(line)


from copy import deepcopy


def update(ary):
    tmp = deepcopy(ary)
    for y in range(h):
        for x in range(w):
            if ary[y][x] == 0:
                if x > 0:
                    tmp[y][x-1] = min(ary[y][x-1], 0)
                if x < w-1:
                    tmp[y][x+1] = min(ary[y][x+1], 0)
                if y > 0:
                    tmp[y-1][x] = min(ary[y-1][x], 0)
                if y < h-1:
                    tmp[y+1][x] = min(ary[y+1][x], 0)
                tmp[y][x] = -1
    return tmp


def init_ary(ary):
    # #. -> 0, 1, 2
    tmp = [[] for i in range(w)]
    for y in range(h):
        for x in range(w):
            tmp[y].append(1 if ary[y][x] == '.' else 0)
    return tmp


def is_all_black(ary):
    return not any(1 in line for line in ary)

ary = init_ary(ary)

count = 0

while not is_all_black(ary):
    ary = update(ary)
    count += 1

print(count)


Fixed submission:
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


from collections import deque

update_q = deque((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

def update(ary, update_q):
    for _ in range(len(update_q)):
        pos = update_q.popleft()
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
    return ary, update_q


black_count = len(update_q)
update_count = 0
while black_count < w * h:
    ary, update_q = update(ary, update_q)
    black_count += len(update_q)
    update_count += 1


print(update_count)

Buggy python submission (verdict: Runtime Error):
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    line = input()
    ary.append(line)

pass


max_val = pow(10, 6)

def convert_ary(ary):
    # #. -> 0, 1, 2
    tmp = [[] for i in range(w)]
    for y in range(h):
        for x in range(w):
            tmp[y].append(None if ary[y][x] == '.' else 0)

    return tmp

ary = convert_ary(ary)

def upd_left(ary, y, x):
    if x == 0:
        return ary
    if ary[y][x-1] is None:
        ary[y][x-1] = ary[y][x] + 1
    else:
        ary[y][x-1] = min(ary[y][x-1], ary[y][x] + 1)
    return ary

def upd_right(ary, y, x):
    if x == w - 1:
        return ary
    if ary[y][x+1] is None:
        ary[y][x+1] = ary[y][x] + 1
    else:
        ary[y][x+1] = min(ary[y][x+1], ary[y][x] + 1)
    return ary

def upd_up(ary, y, x):
    if y == 0:
        return ary
    if ary[y-1][x] is None:
        ary[y-1][x] = ary[y][x] + 1
    else:
        ary[y-1][x] = min(ary[y-1][x], ary[y][x] + 1)
    return ary

def upd_down(ary, y, x):
    if y == h - 1:
        return ary
    if ary[y+1][x] is None:
        ary[y+1][x] = ary[y][x] + 1
    else:
        ary[y+1][x] = min(ary[y+1][x], ary[y][x] + 1)
    return ary

# from copy import deepcopy

def update_ary(ary):
    # tmp = deepcopy(ary)
    for y in range(h):
        for x in range(w):
            if ary[y][x] is None:
                continue
            ary = upd_left(ary, y, x)
            ary = upd_right(ary, y, x)
            ary = upd_up(ary, y, x)
            ary = upd_down(ary, y, x)
    return ary

def is_complete(ary):
    for line in ary:
        if None in line:
            return False
    return True

while not is_complete(ary):
    ary = update_ary(ary)

print(max(elem for line in ary for elem in line))


Fixed submission:
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


from collections import deque

update_q = deque((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

def update(ary, update_q):
    for _ in range(len(update_q)):
        pos = update_q.popleft()
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
    return ary, update_q


black_count = len(update_q)
update_count = 0
while black_count < w * h:
    ary, update_q = update(ary, update_q)
    black_count += len(update_q)
    update_count += 1


print(update_count)

Buggy python submission (verdict: Runtime Error):
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    line = input()
    ary.append(line)

pass


max_val = pow(10, 6)

def convert_ary(ary):
    # #. -> 0, 1, 2
    tmp = [[] for i in range(w)]
    for y in range(h):
        for x in range(w):
            tmp[y].append(None if ary[y][x] == '.' else 0)

    return tmp

ary = convert_ary(ary)

def upd_left(ary, y, x):
    if x == 0:
        return ary
    if ary[y][x-1] is None:
        ary[y][x-1] = ary[y][x] + 1
    else:
        ary[y][x-1] = min(ary[y][x-1], ary[y][x] + 1)
    return ary

def upd_right(ary, y, x):
    if x == w - 1:
        return ary
    if ary[y][x+1] is None:
        ary[y][x+1] = ary[y][x] + 1
    else:
        ary[y][x+1] = min(ary[y][x+1], ary[y][x] + 1)
    return ary

def upd_up(ary, y, x):
    if y == 0:
        return ary
    if ary[y-1][x] is None:
        ary[y-1][x] = ary[y][x] + 1
    else:
        ary[y-1][x] = min(ary[y-1][x], ary[y][x] + 1)
    return ary

def upd_down(ary, y, x):
    if y == h - 1:
        return ary
    if ary[y+1][x] is None:
        ary[y+1][x] = ary[y][x] + 1
    else:
        ary[y+1][x] = min(ary[y+1][x], ary[y][x] + 1)
    return ary

from copy import deepcopy

def update_ary(ary):
    tmp = deepcopy(ary)
    for y in range(h):
        for x in range(w):
            if ary[y][x] is None:
                continue
            tmp = upd_left(ary, y, x)
            tmp = upd_right(ary, y, x)
            tmp = upd_up(ary, y, x)
            tmp = upd_down(ary, y, x)
    return tmp

def is_complete(ary):
    for line in ary:
        if None in line:
            return False
    return True

while not is_complete(ary):
    ary = update_ary(ary)

print(max(elem for line in ary for elem in line))


Fixed submission:
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


from collections import deque

update_q = deque((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

def update(ary, update_q):
    for _ in range(len(update_q)):
        pos = update_q.popleft()
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
    return ary, update_q


black_count = len(update_q)
update_count = 0
while black_count < w * h:
    ary, update_q = update(ary, update_q)
    black_count += len(update_q)
    update_count += 1


print(update_count)