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

H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

q = collections.deque()
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            q.appendleft((i,j))
t = 0
while q:
    tmp = collections.deque()
    while q:
        i,j = q.pop()
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.appendleft((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.appendleft((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.appendleft((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.appendleft((i+1,j))
    q = tmp
    t += 1

print(t-1)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

b = [[True]*(W+2)]
for i in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

#f = open(sys.argv[1], "r")
#input = f.readline

H,W = map(int, input().split())

b = {}
check = set()
i = 0
for h in range(H):
    for c in input().strip():
        if c == "#":
            b[i] = 1
            check.add(i)
        i += 1
t = 0

#import time
#t1 = time.time()

while len(b) != W*H:
    t += 1
    tb = set()
    #print(len(check))
    for i in check:
        if i-W >= 0:
            tb.add(i-W)
        if i%W > 0:
            tb.add(i-1)
        if i%W < W-1:
            tb.add(i+1)
        if i+W < H*W:
            tb.add(i+W)
    check.clear()
    for i in tb:
        if i not in b:
            check.add(i)
        b[i] = 1
print(t)

#print(time.time()-t1)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

f = open(sys.argv[1], "r")
input = f.readline

H,W = map(int, input().split())

b = {}
check = set()
i = 0
for h in range(H):
    for c in input().strip():
        if c == "#":
            b[i] = 1
            check.add(i)
        i += 1
t = 0

#import time
#t1 = time.time()

while len(b) != W*H:
    t += 1
    tb = set()
    #print(len(check))
    for i in check:
        if i-W >= 0:
            tb.add(i-W)
        if i%W > 0:
            tb.add(i-1)
        if i%W < W-1:
            tb.add(i+1)
        if i+W < H*W:
            tb.add(i+W)
    check.clear()
    for i in tb:
        if i not in b:
            check.add(i)
        b[i] = 1
print(t)

#print(time.time()-t1)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

b = []
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            b.append(i)
        i += 1

checked = []
t = 0
while len(checked) != W*H:
    t += 1
    tb = []
    for i in b:
        if i-W >= 0:
            tb.append(i-W)
        if i%W > 0:
            tb.append(i-1)
        if i%W < W-1:
            tb.append(i+1)
        if i+W < H*W:
            tb.append(i+W)
        checked.append(i)
    b = list(set(tb))
    checked = list(set(checked))
"""
    print("<<<< %d >>>>" %(t-1))
    for h in range(H):
        s = ""
        for w in range(W):
            if h*W+w in checked:
                s += "#"
            else:
                s += "."
        print(s)
"""
print(t-1)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

b = []
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            b.append(i)
        i += 1
t = 0
while len(b) != W*H:
    """
    print("<<<< %d >>>>" %(t))
    for h in range(H):
        s = ""
        for w in range(W):
            if h*W+w in b:
                s += "#"
            else:
                s += "."
        print(s)
    """
    t += 1
    tb = []
    for i in b:
        if i-W >= 0:
            tb.append(i-W)
        if i%W > 0:
            tb.append(i-1)
        if i%W < W-1:
            tb.append(i+1)
        if i+W < H*W:
            tb.append(i+W)
    b = list(set(b+tb))
print(t)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

w = [i for i in range(H*W)]
b = []
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            b.append(i)
            w.remove(i)
        i += 1
t = 0
while len(w) > 0:
    """
    print("<<<< %d >>>>" %(t))
    print(b)
    print(w)
    for hh in range(H):
        s = ""
        for ww in range(W):
            if hh*W+ww in b:
                s += "#"
            else:
                s += "."
        print(s)
    """
    t += 1
    tb = []
    for i in b:
        if i-W >= 0 and i-W in w:
            w.remove(i-W)
            tb.append(i-W)
        if i%W > 0 and i-1 in w:
            w.remove(i-1)
            tb.append(i-1)
        if i%W < W-1 and i+1 in w:
            w.remove(i+1)
            tb.append(i+1)
        if i+W < H*W and i+W in w:
            w.remove(i+W)
            tb.append(i+W)
    for i in tb:
        if i not in b:
            b.append(i)
    b.remove(i)
print(t)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

a = set()
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            a.add(i)
        i += 1
#print(a)

m = 0
for i in range(H*W):
    ni = H+W-2
    if i in a:
        ni = 0
    else:
        for j in a:
            ni = min(ni, abs(j//W-i//W) + abs(j%W -i%W))
            if ni == 1:
                break
#            print(ni, abs(j-i)//W, abs(j%W -i%W))
    m = max(m, ni)
print(m)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

a = set()
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            a.add(i)
        i += 1
#print(a)

m = 0
for i in range(H*W):
    ni = H+W-2
    if i in a:
        ni = 0
    else:
        for j in a:
            ni = min(ni, abs(j//W-i//W) + abs(j%W -i%W))
#            print(ni, abs(j-i)//W, abs(j%W -i%W))
    m = max(m, ni)
print(m)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

a = set()
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            a.add(i)
        i += 1
#print(a)

m = 0
for i in range(H*W):
    ni = H+W-2
    for j in a:
        ni = min(ni, abs(j//W-i//W) + abs(j%W -i%W))
#        print(ni, abs(j-i)//W, abs(j%W -i%W))
    m = max(m, ni)
print(m)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)

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

H,W = map(int, input().split())

a = []
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            a.append(i)
        i += 1
#print(a)

m = 0
for i in range(H*W):
    ni = H+W-2
    for j in a:
        ni = min(ni, abs(j//W-i//W) + abs(j%W -i%W))
#        print(ni, abs(j-i)//W, abs(j%W -i%W))
    m = max(m, ni)
print(m)


Fixed submission:
import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)