Buggy python submission (verdict: Time Limit Exceeded):
class TupleQueue:

    def __init__(self, bufsize):
        self.start = 0
        self.end = 0
        self.buffer = [(None, None) for _ in range(bufsize)]

    def enqueue(self, t):
        self.buffer[self.end] = t
        self.end += 1

    def dequeue(self):
        if self.start != self.end:
            item = self.buffer[self.start]
            self.start += 1
            return item
        return None

    def clear(self):
        self.start = 0
        self.end = 0

    def is_empty(self):
        if self.start == self.end:
            return True
        return False


h, w = map(int, input().split())
que = TupleQueue(h * w)
nxt = TupleQueue(h * w)

data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.enqueue((ln, r))

count = 0

while que.is_empty() is False:
    count += 1
    while que.is_empty() is False:
        row, col = que.dequeue()
        for r, c in ((row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)):
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                nxt.enqueue((r, c))
                data[r][c] = '#'
    que, nxt = nxt, que
    nxt.clear()

print(count - 1)


Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
que = deque(maxlen=h * w)
next = deque(maxlen=h * w)

data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0

while len(que) > 0:
    count += 1
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in ((row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)):
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que, next = next, que
    next.clear()

print(count - 1)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
H,W = map(int, input().split())
A = []
for _ in range(H):
    v = 0
    for w, x in zip(range(W), input()):
        if x == "#":
            v |= 1 << w
    A += [ v ]

import numpy as np


A = np.array(A)
WK = np.zeros(A.shape)
MASK = pow(2, W) - 1
MASKSUM = MASK * H
i = 0
while True:
    if np.sum(A) == MASKSUM:
        break
    WK = 0+A
    A[:-1] |= WK[1:]
    A[1:] |= WK[:-1]
    A |= ((WK << 1)&MASK) | (WK >> 1)
    i += 1

print(i)


Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
A = []
for _ in range(H):
    v = 0
    for w, x in zip(range(W), input()):
        if x == "#":
            v |= 1 << w
    A += [ v ]

import numpy as np


A = np.array(A)
WK = np.zeros(A.shape)
MASK = pow(2, W) - 1
MASKSUM = MASK * H
i = 0
while True:
    if np.sum(A) == MASKSUM:
        break
    WK = 0+A
    A[:-1] |= WK[1:]
    A[1:] |= WK[:-1]
    A |= ((WK << 1)&MASK) | (WK >> 1)
    i += 1

print(i)


Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
que = deque(maxlen=h * w)
next = deque(maxlen=h * w)

data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0

while len(que) > 0:
    count += 1
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in ((row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)):
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que, next = next, que
    next.clear()

print(count - 1)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
black = {}
white = {}

for ln in range(h):
    line = input().rstrip()
    for i, letter in enumerate(line):
        if letter == '.':
            white[(ln, i)] = letter
        elif letter == '#':
            black[(ln, i)] = letter

count = 0


while len(white) > 0:
    count += 1
    next = {}
    for row, col in black.keys():
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if white.get((r, c)):
                next[(r, c)] = white.pop((r, c))
    black.clear()
    for k, v in next.items():
        black[k] = v

print(count)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
black = {}
white = {}

for ln in range(h):
    line = input().rstrip()
    for i, letter in enumerate(line):
        if letter == '.':
            white[(ln, i)] = letter
        elif letter == '#':
            black[(ln, i)] = letter

count = 0


while len(white) > 0:
    count += 1
    next = {}
    for row, col in black.keys():
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if white.get((r, c)):
                next[(r, c)] = white.pop((r, c))
    black.clear()
    for k, v in next.items():
        black[k] = v

print(count)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
black = {}
white = {}

for ln in range(h):
    line = input().rstrip()
    for i, letter in enumerate(line):
        if letter == '.':
            white[(ln, i)] = letter
        elif letter == '#':
            black[(ln, i)] = letter

count = 0
while len(white) > 0:
    count += 1
    removed = {}
    for row, col in white.keys():
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if black.get((r, c)):
                removed[(row, col)] = white.get((row, col))
                break
    for k, v in removed.items():
        white.pop(k)
        black[k] = v


print(count)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
h, w = map(int, input().split())
data = []
for n in range(h):
    data.append(list(input().rstrip()))


def data_have_dot():
    # print(data)
    for row in data:
        if row.count('.') > 0:
            return True
    return False


count = 0
while data_have_dot():
    count += 1
    copy = deepcopy(data)
    for l in range(h):
        for r in range(w):
            if copy[l][r] == '#':
                if l > 0:
                    data[l - 1][r] = '#'
                if l < h - 1:
                    data[l + 1][r] = '#'
                if r > 0:
                    data[l][r - 1] = '#'
                if r < w - 1:
                    data[l][r + 1] = '#'

print(count)


Fixed submission:
from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)