Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np
 
num = list(map(int,input().split()))
field = [list(input()) for i in range(num[0])]
q_r = deque([])
q_c = deque([])
seen = np.zeros((num[0],num[1]))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]
 
for i in range(num[0]):
  for j in range(num[1]):
    if field[i][j] == "#":
      q_r.append(i)
      q_c.append(j)
      g_r = i
      g_c = j
 
while q_r:
  r = q_r.popleft()
  c = q_c.popleft()
 
  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (next_r<0) or (num[0]<=next_r) or (next_c<0) or (num[1]<=next_c) or (field[next_r][next_c] == "#"):
      continue
    
    field[next_r][next_c] = "#"
    q_r.append(next_r)
    q_c.append(next_c)
    seen[next_r][next_c] = seen[r][c] + 1
#    print(seen[next_r][next_c],next_r,next_c)
    g_r = next_r
    g_c = next_c
 
print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = []
for i in range(h):
    a.append(input())

used = [True]*(h*w)

p = []
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            p.append(i*w+j)
            used[i*w+j] = False
 
 
res = 0
while p:
    tank = []
    for e in p:
        if e>w-1 and used[e-w]:
            tank.append(e-w)
            used[e-w] = False
        if e%w > 0 and used[e-1]:
            tank.append(e-1)
            used[e-1] = False
        if e<(h-1)*w and used[e+w]:
            tank.append(e+w)
            used[e+w] = False
        if e%w<w-1 and used[e+1]:
            tank.append(e+1)
            used[e+1] =  False
    p = tank
    res += 1
print(res-1)

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  num_r,num_c = map(int,input().split())
  field = [input() for i in range(num_r)]
  q = []
  seen = [0]*(num_c*num_r)
  count = 0

  for i in range(num_r):
    for j in range(num_c):
      if field[i][j] == "#":
        seen[i*num_c+j] = 1
        q.append([i,j])
      
  while q:
    tank = []
    for i in q:
      r = i[0]
      c = i[1]
      if (0<=r-1) and (seen[(r-1)*num_c+c] == 0):
        tank.append([r-1,c])
        seen[(r-1)*num_c+c] = 1
      if (r+1<num_r) and (seen[(r+1)*num_c+c] == 0):
        tank.append([r+1,c])
        seen[(r+1)*num_c+c] = 1
      if (0<=c-1) and (seen[r*num_c+(c-1)] == 0):
        tank.append([r,c-1])
        seen[r*num_c+(c-1)] = 1
      if (c+1<num_c) and (seen[r*num_c+(c+1)] == 0):
        tank.append([r,c+1])
        seen[r*num_c+(c+1)] = 1

    count = count + 1
    q = tank

  print(count-1)
  
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
  num_r,num_c = map(int,input().split())
  field = [input() for i in range(num_r)]
  q = []
  seen = [0]*(num_c*num_r)
  count = 0

  for i in range(num_r):
    for j in range(num_c):
      if field[i][j] == "#":
        seen[i*num_c+j] = 1
        q.append(i*num_c+j)

  while q:
    tank = []
    for i in q:
      if (0<=i-num_c) and (seen[i-num_c] == 0):
        tank.append(i-num_c)
        seen[i-num_c] = 1
      if (i+num_c<num_c*num_r) and (seen[i+num_c] == 0):
        tank.append(i+num_c)
        seen[i+num_c] = 1
      if (0<=i%num_c -1) and (seen[i-1] == 0):
        tank.append(i-1)
        seen[i-1] = 1
      if (i%num_c+1<num_r) and (seen[i+1] == 0):
        tank.append(i+1)
        seen[i+1] = 1

    count = count + 1
    q = tank

  print(count-1)
  
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = []
for i in range(h):
  a.append(input())
 
  used = [True]*(h*w)
  
p = []
for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      p.append(i*w+j)
      used[i*w+j] = False
 
 
    
res = 0
while p:
    tank = []
    for e in p:
        if e>w-1 and used[e-w]:
            tank.append(e-w)
            used[e-w] = False
        if e%w > 0 and used[e-1]:
            tank.append(e-1)
            used[e-1] = False
        if e<(h-1)*w and used[e+w]:
            tank.append(e+w)
            used[e+w] = False
        if e%w<w-1 and used[e+1]:
            tank.append(e+1)
            used[e+1] =  False
    p = tank
    res += 1
print(res-1)

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

  used = [True]*(h*w)

  p = []
  for i in range(h):
    for j in range(w):
      if a[i][j] == '#':
        p.append(i*w+j)
        used[i*w+j] = False
 
 
    
res = 0
while p:
    tank = []
    for e in p:
        if e>w-1 and used[e-w]:
            tank.append(e-w)
            used[e-w] = False
        if e%w > 0 and used[e-1]:
            tank.append(e-1)
            used[e-1] = False
        if e<(h-1)*w and used[e+w]:
            tank.append(e+w)
            used[e+w] = False
        if e%w<w-1 and used[e+1]:
            tank.append(e+1)
            used[e+1] =  False
    p = tank
    res += 1
print(res-1)

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num_r,num_c = map(int,input().split())
field = [input() for i in range(num_r)]
q = []
seen = [0]*(num_c*num_r)
count = 0

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      seen[i*num_c+j] = 1
      q.append(i*num_c+j)

while q:
  tank = []
  for i in q:
    if (0<=i-num_c) and (seen[i-num_c] == 0):
      tank.append(i-num_c)
      seen[i-num_c] = 1
    if (i+num_c<num_c*num_r) and (seen[i+num_c] == 0):
      tank.append(i+num_c)
      seen[i+num_c] = 1
    if (0<=i%num_c-1) and (seen[i-1] == 0):
      tank.append(i-1)
      seen[i-1] = 1
    if (i%num_c+1<num_r) and (seen[i+1] == 0):
      tank.append(i+1)
      seen[i+1] = 1
   
  count = count + 1
  q = tank

print(count-1)

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
num_r,num_c = map(int,input().split())
field = [input() for i in range(num_r)]
q = []
seen = [0]*(num_c*num_r)
count = 0

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      seen[i*num_c+j] = 1
      q.append([i,j])

while q:
  tank = []
  for i in q:
    r = i[0]
    c = i[1]
    if (0<=r-1) and (seen[(r-1)*num_c+c] == 0):
      tank.append([r-1,c])
      seen[(r-1)*num_c+c] = 1
    if (r+1<num_r) and (seen[(r+1)*num_c+c] == 0):
      tank.append([r+1,c])
      seen[(r+1)*num_c+c] = 1
    if (0<=c-1) and (seen[r*num_c+(c-1)] == 0):
      tank.append([r,c-1])
      seen[r*num_c+(c-1)] = 1
    if (c+1<num_c) and (seen[r*num_c+(c+1)] == 0):
      tank.append([r,c+1])
      seen[r*num_c+(c+1)] = 1
   
  count = count + 1
  q = tank

print(count-1)

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num_r,num_c = map(int,input().split())
field = [input() for i in range(num_r)]
q = deque([])
seen = [0]*(num_c*num_r)
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      q.append([i,j])

while q:
  now_q = q.popleft()
  r = now_q[0]
  c = now_q[1]

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (0 <= next_r < num_r) and (0 <= next_c < num_c) and (field[next_r][next_c] != "#") and (seen[next_r*num_c+next_c] == 0):
      q.append([next_r,next_c])
      seen[next_r*num_c+next_c] = seen[r*num_c+c] + 1
  #    print(seen[next_r][next_c],next_r,next_c)
      g_r = next_r
      g_c = next_c

print(int(seen[g_r*num_c+g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num_r,num_c = map(int,input().split())
field = [list(input()) for i in range(num_r)]
q = deque([])
seen = [[0]*num_c for i in range(num_r)]
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      q.append([i,j])

while q:
  now_q = q.popleft()
  r = now_q[0]
  c = now_q[1]

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (0 <= next_r < num_r) and (0 <= next_c < num_c) and (field[next_r][next_c] != "#"):
      field[next_r][next_c] = "#"
      q.append([next_r,next_c])
      seen[next_r][next_c] = seen[r][c] + 1
  #    print(seen[next_r][next_c],next_r,next_c)
      g_r = next_r
      g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num_r,num_c = map(int,input().split())
field = [list(input()) for i in range(num_r)]
q_r = deque([])
q_c = deque([])
seen = [[0]*num_c for i in range(num_r)]
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      q_r.append(i)
      q_c.append(j)
      g_r = 0
      g_c = 0

while q_r:
  r = q_r.popleft()
  c = q_c.popleft()

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (0 <= next_r < num_r) and (0 <= next_c < num_c) and (field[next_r][next_c] != "#"):
      field[next_r][next_c] = "#"
      q_r.append(next_r)
      q_c.append(next_c)
      seen[next_r][next_c] = seen[r][c] + 1
  #    print(seen[next_r][next_c],next_r,next_c)
      g_r = next_r
      g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num_r,num_c = map(int,input().split())
field = [list(input()) for i in range(num_r)]
q_r = deque([])
q_c = deque([])
seen = np.zeros((num_r,num_c))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      q_r.append(i)
      q_c.append(j)
      g_r = 0
      g_c = 0

while q_r:
  r = q_r.popleft()
  c = q_c.popleft()

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (0 <= next_r < num_r) and (0 <= next_c < num_c) and (field[next_r][next_c] != "#"):
      field[next_r][next_c] = "#"
      q_r.append(next_r)
      q_c.append(next_c)
      seen[next_r][next_c] = seen[r][c] + 1
  #    print(seen[next_r][next_c],next_r,next_c)
      g_r = next_r
      g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num_r,num_c = map(int,input().split())
field = [list(input()) for i in range(num_r)]
q_r = deque([])
q_c = deque([])
seen = np.zeros((num_r,num_c))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      q_r.append(i)
      q_c.append(j)
      g_r = 0
      g_c = 0

while q_r:
  r = q_r.popleft()
  c = q_c.popleft()

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (next_r<0) or (num_r<=next_r) or (next_c<0) or (num_c<=next_c) or (field[next_r][next_c] == "#"):
      continue
    
    field[next_r][next_c] = "#"
    q_r.append(next_r)
    q_c.append(next_c)
    seen[next_r][next_c] = seen[r][c] + 1
#    print(seen[next_r][next_c],next_r,next_c)
    g_r = next_r
    g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num_r,num_c = list(map(int,input().split()))
field = [list(input()) for i in range(num_r)]
q_r = deque([])
q_c = deque([])
seen = np.zeros((num_r,num_c))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      q_r.append(i)
      q_c.append(j)
      g_r = 0
      g_c = 0

while q_r:
  r = q_r.popleft()
  c = q_c.popleft()

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (next_r<0) or (num_r<=next_r) or (next_c<0) or (num_c<=next_c) or (field[next_r][next_c] == "#"):
      continue
    
    field[next_r][next_c] = "#"
    q_r.append(next_r)
    q_c.append(next_c)
    seen[next_r][next_c] = seen[r][c] + 1
#    print(seen[next_r][next_c],next_r,next_c)
    g_r = next_r
    g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

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

num = list(map(int,input().split()))
field = [list(input()) for i in range(num[0])]
q_r = deque([])
q_c = deque([])
seen = np.zeros((num[0],num[1]))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num[0]):
  for j in range(num[1]):
    if field[i][j] == "#":
      q_r.append(i)
      q_c.append(j)
      g_r = 0
      g_c = 0

while q_r:
  r = q_r.popleft()
  c = q_c.popleft()

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (next_r<0) or (num[0]<=next_r) or (next_c<0) or (num[1]<=next_c) or (field[next_r][next_c] == "#"):
      continue
    
    field[next_r][next_c] = "#"
    q_r.append(next_r)
    q_c.append(next_c)
    seen[next_r][next_c] = seen[r][c] + 1
#    print(seen[next_r][next_c],next_r,next_c)
    g_r = next_r
    g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import queue
import numpy as np

num = list(map(int,input().split()))
field = [list(input()) for i in range(num[0])]
q_r = queue.Queue()
q_c = queue.Queue()
seen = np.zeros((num[0],num[1]))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num[0]):
  for j in range(num[1]):
    if field[i][j] == "#":
      q_r.put(i)
      q_c.put(j)
      g_r = 0
      g_c = 0
      
while not q_r.empty():
  r = q_r.get()
  c = q_c.get()
  
  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (next_r<0) or (num[0]<=next_r) or (next_c<0) or (num[1]<=next_c) or (field[next_r][next_c] == "#"):
      continue
    
    field[next_r][next_c] = "#"
    q_r.put(next_r)
    q_c.put(next_c)
    seen[next_r][next_c] = seen[r][c] + 1
#    print(seen[next_r][next_c],next_r,next_c)
    g_r = next_r
    g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import queue
import numpy as np

num = list(map(int,input().split()))
field = [list(input()) for i in range(num[0])]
q_r = queue.Queue()
q_c = queue.Queue()
seen = np.zeros((num[0],num[1]))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num[0]):
  for j in range(num[1]):
    if field[i][j] == "#":
      q_r.put(i)
      q_c.put(j)
      
while not q_r.empty():
  r = q_r.get()
  c = q_c.get()
  
  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (next_r<0) or (num[0]<=next_r) or (next_c<0) or (num[1]<=next_c) or (field[next_r][next_c] == "#"):
      continue
    
    field[next_r][next_c] = "#"
    q_r.put(next_r)
    q_c.put(next_c)
    seen[next_r][next_c] = seen[r][c] + 1
#    print(seen[next_r][next_c],next_r,next_c)
    g_r = next_r
    g_c = next_c

print(int(seen[g_r][g_c]))

Fixed submission:
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()