Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys

input = sys.stdin.readline

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
q = deque()
visited = [[W+H]*W for _ in range(H)]
for i in range(H):
    for j, s in enumerate(input()):
        if s == '#':
            visited[i][j] = 0
            q.append((i, j, 0))

res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    if 0 <= y+1 < H and visited[y+1][x] > lv+1:
        visited[y+1][x] = lv+1
        q.append((y+1, x, lv+1))

    if 0 <= y-1 < H and visited[y-1][x] > lv+1:
        visited[y-1][x] = lv+1
        q.append((y-1, x, lv+1))

    if 0 <= x+1 < W and visited[y][x+1] > lv+1:
        visited[y][x+1] = lv+1
        q.append((y, x+1, lv+1))

    if 0 <= x-1 < W and visited[y][x-1] > lv+1:
        visited[y][x-1] = lv+1
        q.append((y, x-1, lv+1))

print(res)

Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
input = sys.stdin.readline

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
edge = ['#'] * (W + 2)
visited = [H+W]*(H*W)
field = [edge]
q = deque()

for i in range(H):
    line = input()
    field.append(['#'] + list(line) + ['#'])
    for j in range(W):
        if line[j] == '#':
            q.append((i + 1, j + 1, 0))

field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()

    if 0 <= y+1 < H and visited[(y+1)*W+x] > lv:
        visited[(y+1)*W+x] = lv
        q.append((y+1, x, lv+1))

    if 0 <= y-1 < H and visited[(y-1)*W+x] > lv:
        visited[(y-1)*W+x] = lv
        q.append((y - 1, x, lv + 1))

    if 0 <= x+1 < W and visited[y*W+x+1] > lv:
        visited[y*W+x+1] = lv
        q.append((y, x+1, lv + 1))

    if 0 <= x-1 < W and visited[y*W+x-1] > lv:
        visited[y*W+x-1] = lv
        q.append((y, x-1, lv + 1))

print(max(visited))

Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
edge = ['#'] * (W + 2)
field = [edge]
q = deque()

for i in range(H):
    line = input()
    field.append(['#'] + list(line) + ['#'])
    for j in range(W):
        if line[j] == '#':
            q.append((i + 1, j + 1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    if field[y + 1][x] == '.':
        field[y + 1][x] = '#'
        q.append((y + 1, x, lv + 1))

    if field[y - 1][x] == '.':
        field[y - 1][x] = '#'
        q.append((y - 1, x, lv + 1))

    if field[y][x+1] == '.':
        field[y][x+1] = '#'
        q.append((y, x+1, lv + 1))

    if field[y][x-1] == '.':
        field[y][x-1] = '#'
        q.append((y, x-1, lv + 1))

print(res)

Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
edge = ['#'] * (W + 2)
field = [edge]
q = deque()

for i in range(H):
    line = input()
    field.append(['#'] + list(line) + ['#'])
    for j in range(W):
        if line[j] == '#':
            q.append((i + 1, j + 1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    if field[y + 1][x] == '.':
        field[y + 1][x] = '#'
        q.append((y + 1, x, lv + 1))

    if field[y - 1][x] == '.':
        field[y - 1][x] = '#'
        q.append((y - 1, x, lv + 1))

    if field[y][x+1] == '.':
        field[y][x+1] = '#'
        q.append((y, x+1, lv + 1))

    if field[y][x-1] == '.':
        field[y][x-1] = '#'
        q.append((y, x-1, lv + 1))

print(res)

Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
visited = [False]*(H*W)
q = deque()

field = [input() for _ in range(H)]
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            visited[i*W+j] = True
            q.append((i, j, 0))

res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    for dy, dx in dyx:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and visited[ny*W+nx] == False:
            visited[ny*W+nx] = True
            q.append((ny, nx, lv+1))

print(res)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
visited = [False]*(H*W)
q = deque()

for i in range(H):
    line = input()
    for j in range(W):
        if line[j] == '#':
            q.append((i, j, 0))
            visited[i*W+j] = True

res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    for dy, dx in dyx:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and visited[ny*W+nx] == False:
            visited[ny*W+nx] = True
            q.append((ny, nx, lv+1))

print(res)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Runtime Error):
from collections import deque

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
visited = [0]*(H*W)
q = deque()

for i in range(H):
    line = input()
    for j in range(W):
        if line[j] == '#':
            q.append((i, j, 0))
            visited[i*H+j] = 1

res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    for dy, dx in dyx:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and visited[ny*H+nx] == 0:
            visited[ny*H+nx] = 1
            q.append((ny, nx, lv+1))

print(res)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
edge = ['#'] * (W + 2)
field = [edge]
q = deque()

for i in range(H):
    line = input()
    field.append(['#'] + list(line) + ['#'])
    for j in range(W):
        if line[j] == '#':
            q.append((i + 1, j + 1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    for dy, dx in dyx:
        if field[y + dy][x + dx] == '.':
            field[y + dy][x + dx] = '#'
            q.append((y + dy, x + dx, lv + 1))

print(res)

Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
field = list(list(input()) for _ in range(H))
q = deque()
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            field[i][j] = 1
            q.append((i, j, 0))
        else:
            field[i][j] = 0

res = 0
while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    for dy, dx in dyx:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and field[ny][nx] == 0:
            field[ny][nx] = 1
            q.append((ny, nx, lv+1))

print(res)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = ((0, 1), (0, -1), (1, 0), (-1, 0))
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    line = input()
    field.append(['#'] + list(line) + ['#'])
    for j in range(W):
        if line[j] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    if lv > res:
        res = lv

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    line = input()
    field.append(['#'] + list(line) + ['#'])
    for j in range(W):
        if line[j] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if not field[y+dy][x+dx] == '#':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Runtime Error):

H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
ans = 0


def change(x, y):
    if x < 0 or x >= W:
        return False
    if y < 0 or y >= H:
        return False

    if G[x][y] == ".":
        G[x][y] = "@"
        return False
    elif G[x][y] == "#":
        return True


def search(x, y):
    global ans
    count = 0
    sharp = 0

    while sharp == 0:
        if count == 0:
            G[x][y] = "@"
        else:
            for i in range(count+1):
                if change(x+count-i, y+1) or change(x-i, y+count-i) or \
                    change(x-count+i, y-i) or change(x+i, y-count+i):
                    sharp += 1

        if count > ans:
            ans = count

        count += 1


for i in range(H):
    for j in range(W):
        if G[i][j] == ".":
            search(i, j)

print(ans)




Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
ans = 0


def change(x, y):
    if x < 0 or x >= W:
        return False
    if y < 0 or y >= H:
        return False

    if G[x][y] == ".":
        G[x][y] = "@"
        return False
    elif G[x][y] == "#":
        return True


def search(x, y):
    global ans
    count = 0
    sharp = 0

    while sharp == 0:
        if count == 0:
            G[x][y] = "@"
        else:
            for i in range(count+1):
                if change(x+count-i, y+1) or change(x-i, y+count-i) or \
                    change(x-count+i, y-i) or change(x+i, y-count+i):
                    sharp += 1

        if count > ans:
            ans = count

        count += 1


for i in range(H):
    for j in range(W):
        if G[i][j] == ".":
            search(j, i)

print(ans)



Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
pG = copy.deepcopy(G)
ans = 0

while True:
    count = 0
    for i in range(H):
        for j in range(W):
            if G[i][j] == "#":
                count += 1
                try:
                    if i-1 >= 0:
                        pG[i-1][j] = "#"
                    if j-1 >= 0:
                        pG[i][j-1] = "#"
                    pG[i+1][j] = "#"
                    pG[i][j+1] = "#"
                except IndexError:
                    pass
    if count == W*H:
        break
    ans += 1
    G = copy.deepcopy(pG)

print(ans)


Fixed submission:
from collections import deque

dyx = [(0, 1), (0, -1), (1, 0), (-1, 0)]
H, W = map(int, input().split())
edge = ['#']*(W+2)
field = [edge]
q = deque()

for i in range(H):
    field.append(['#'] + list(input()) + ['#'])
    for j in range(W):
        if field[i+1][j+1] == '#':
            q.append((i+1, j+1, 0))
field.append(edge)
res = 0

while q:
    y, x, lv = q.popleft()
    res = max(lv, res)

    for dy, dx in dyx:
        if field[y+dy][x+dx] == '.':
            field[y+dy][x+dx] = '#'
            q.append((y+dy, x+dx, lv+1))

print(res)