Problem p03006 (python)

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

    ans = num
    for i in range(num):
        for j in range(num):
            if i == j:
                continue

            kyori = [data[i][0] - data[j][0], data[i][1] - data[j][1]]
            visit_list = [0 for i in range(num)]

            kari_num = 0

            for k in range(num):

                if visit_list[k]:
                    continue
                kari_num += 1
                visit_list[k] = 1
                flg = 1
                now_place = [data[k][0] + kyori[0], data[k][1] + kyori[1]]
                now_place_rev = [data[k][0] - kyori[0], data[k][1] - kyori[1]]

                while flg:
                    flg = 0
                    for l in range(num):
                        if visit_list[l]:
                            continue
                        if data[l] == now_place:
                            now_place = [now_place[0] + kyori[0], now_place[1] + kyori[1]]
                            visit_list[l] = 1
                            flg = 1
                        if data[l] == now_place_rev:
                            now_place_rev = [now_place_rev[0] - kyori[0], now_place_rev[1] - kyori[1]]
                            visit_list[l] = 1
                            flg = 1

            ans = min(ans, kari_num)




    print(ans)






if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

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


    ans = num

    for i in range(num):
        for j in range(num):
            if i == j:
                continue

            now_kyori = [data[i][0] - data[j][0], data[i][1] - data[j][1]]
            visit_list = [0 for i in range(num)]
            visit_list[i], visit_list[j] = 1, 1

            kari_num = 1

            for k in range(num):
                if visit_list[k]:
                    continue

                now_data = data[k]

                flg = 1
                for l in range(num):
                    if visit_list[l]:
                        a = data[l][0] - now_data[0]
                        b = data[l][1] - now_data[1]

                        if now_kyori[0] == 0 and now_kyori[1] == 0:
                            if a == now_kyori[0] and b == now_kyori[0]:
                                flg = 0
                        elif now_kyori[0] == 0:
                            if a == now_kyori[0] and b % now_kyori[1] == 0:
                                if b // now_kyori[1] == 1 or b // now_data[1] == -1:
                                    flg = 0
                        elif now_kyori[1] == 0:
                            if b == now_kyori[1] and a % now_kyori[0] == 0:
                                if a // now_kyori[0] == 1 or a // now_data[0] == -1:
                                    flg = 0
                        else:
                            if a % now_kyori[0] == 0 and b % now_kyori[1] == 0:
                                if a // now_kyori[0] == b // now_kyori[1]:
                                    if a // now_data[0] == 1 or a // now_data[1] == -1:
                                        flg = 0
                        if flg == 0:
                            break

                if flg:
                    kari_num += 1
                visit_list[k] = 1


            ans = min(kari_num, ans)

    print(ans)






if __name__ == '__main__':
    main()