Buggy python submission (verdict: Time Limit Exceeded):

from queue import Queue



def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    q = Queue()
    q_next = Queue()

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                q.put([i, j])

    count = 0

    while 1:
        while 1:
            if q.empty():
                break

            now_data = q.get()
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    q_next.put([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    q_next.put([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    q_next.put([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    q_next.put([a, b])
                    data[a][b] = '#'

        q = q_next
        q_next = Queue()


        if q.empty():
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()


Fixed submission:
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = set()
    next_list = set()

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                c = '{}_{}'.format(i, j)
                now_list.add(c)

    count = 0

    while 1:
        for now_data in now_list:
            i, j = map(int, now_data.split('_'))

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    c = '{}_{}'.format(a, b)
                    next_list.add(c)
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    c = '{}_{}'.format(a, b)
                    next_list.add(c)
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    c = '{}_{}'.format(a, b)
                    next_list.add(c)
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    c = '{}_{}'.format(a, b)
                    next_list.add(c)
                    data[a][b] = '#'

        now_list = next_list
        next_list = set()


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)

def kari():
    high, width = 1000, 1000
    a = set()
    for i in range(high):
        for j in range(width):
            a.add(j)
        a = set()

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()

Fixed submission:
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
import math

def kari():
    map(int, input().split())
    list(map(int, input().split()))


def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = set()
    next_list = set()
    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.add('{}_{}'.format(i, j))


    count = 0

    while 1:
        flg = 0
        for now_data in now_list:
            i, j = map(int, now_data.split('_'))
            data[i][j] = '#'

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

            if kari_j1 >= 0:
                a, b = i, kari_j1
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                c = '{}_{}'.format(a, b)
                if data[a][b] == '.':
                    if c not in next_list:
                        next_list.add(c)
                        flg = 1

        now_list = next_list
        next_list = set()


        if flg == 0:
            break
        else:
            count += 1


    print(count)




if __name__ == '__main__':
    main()

Fixed submission:
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
import math

def kari():
    map(int, input().split())
    list(map(int, input().split()))


def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []
    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])


    count = 0

    while 1:
        flg = 0
        pre_dic = set()
        for now_data in now_list:
            i, j = now_data
            data[i][j] = '#'

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                if data[kari_i1][j] == '.' and [kari_i1, j] not in next_list:
                    next_list.append([kari_i1, j])
                    flg = 1
            if kari_i2 <= high - 1:
                if data[kari_i2][j] == '.' and [kari_i2, j] not in next_list:
                    next_list.append([kari_i2, j])
                    flg = 1
            if kari_j1 >= 0:
                if data[i][kari_j1] == '.' and [i, kari_j1] not in next_list:
                    next_list.append([i, kari_j1])
                    flg = 1
            if kari_j2 <= width - 1:
                if data[i][kari_j2] == '.' and [i, kari_j2] not in next_list:
                    next_list.append([i, kari_j2])
                    flg = 1

        now_list = next_list.copy()
        next_list = []

        # print('uuuu')
        # print(i, j)
        # print(now_list)


        if flg == 0:
            break
        else:
            count += 1

        # check_count = count
        # count = str(int(count) + 1)

        # print('------')
        # for i in range(high):
        #     print(''.join(data[i]))
    #
    # print('------')
    # for i in range(high):
    #     print(''.join(data[i]))

    # print(check_count)

    print(count)




if __name__ == '__main__':
    main()

Fixed submission:
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
import math

def kari():
    map(int, input().split())
    list(map(int, input().split()))


def main():
    high, width = map(int, input().split())
    data = [list(input().replace('#', '0')) for i in range(high)]

    count = '1'
    check_count = '0'
    while 1:
        flg = 0
        for i in range(high):
            for j in range(width):
                if data[i][j] == check_count:
                    kari_i1, kari_i2 = i - 1, i + 1
                    kari_j1, kari_j2 = j - 1, j + 1

                    if kari_i1 >= 0:
                        if data[kari_i1][j] == '.':
                            data[kari_i1][j] = count
                            flg = 1
                    if kari_i2 <= high - 1:
                        if data[kari_i2][j] == '.':
                            data[kari_i2][j] = count
                            flg = 1
                    if kari_j1 >= 0:
                        if data[i][kari_j1] == '.':
                            data[i][kari_j1] = count
                            flg = 1
                    if kari_j2 <= width - 1:
                        if data[i][kari_j2] == '.':
                            data[i][kari_j2] = count
                            flg = 1

        if flg == 0:
            break

        check_count = count
        count = str(int(count) + 1)

    #     print('------')
    #     for i in range(high):
    #         print(''.join(data[i]))
    #
    # print('------')
    # for i in range(high):
    #     print(''.join(data[i]))

    print(check_count)




if __name__ == '__main__':
    main()

Fixed submission:
def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    now_list = []
    next_list = []

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                now_list.append([i, j])

    count = 0

    while 1:
        for now_data in now_list:
            i, j = now_data

            kari_i1, kari_i2 = i - 1, i + 1
            kari_j1, kari_j2 = j - 1, j + 1

            if kari_i1 >= 0:
                a, b = kari_i1, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_i2 <= high - 1:
                a, b = kari_i2, j
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j1 >= 0:
                a, b = i, kari_j1
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

            if kari_j2 <= width - 1:
                a, b = i, kari_j2
                if data[a][b] == '.':
                    next_list.append([a, b])
                    data[a][b] = '#'

        now_list = next_list
        next_list = []


        if len(now_list) == 0:
            break
        else:
            count += 1


    print(count)



if __name__ == '__main__':
    main()