Problem p03006 (python)

Fixed submission:
n = int(input())
a = [tuple(map(int,input().split())) for i in range(n)]

m = dict()


ans = 0


for i in range(n):
    for j in range(n):
        if i !=j:
            x = a[i][0] - a[j][0]
            y = a[i][1] - a[j][1]

            p = (x,y)

            if p not in m:
                m[p] = 0

            m[p] += 1

            ans = max(m[p], ans)



print(n-ans)

Buggy submission (verdict: Runtime Error):

def check_other(tmp_i, cur_p, cur_q, cur_x, cur_y, tmp_count):
    for i in range(len(p)):
        if i in tmp_i:
            continue

        tmp_p = p[i][0] - cur_x
        tmp_q = p[i][1] - cur_y

        if tmp_p == cur_p and tmp_q == cur_q:
            tmp_i.append(i)

            tmp_count += 1
            tmp_count = check_other(tmp_i, cur_p, cur_q, p[i][0], p[i][1], tmp_count)


    return tmp_count





if __name__ == "__main__":
    #入力取得
    N = int(input())

    p = []


    for i in range(N):
        l = list(map(int, input().split()))
        p.append(l)

    min_cost = N

    results = []

    counts = []

    for j in range(len(p)):
        for i in range(len(p)):
            tmp_i = [i]
            tmp_count = 0
            if i == 0:
                continue

            tmp_p = p[i][0] - p[j][0]
            tmp_q = p[i][1] - p[j][1]



            tmp_count = check_other(tmp_i, tmp_p, tmp_q, p[i][0], p[i][1], tmp_count)


            counts.append(tmp_count)




tmp_max = max(counts)

if N == 2:
    result = 1
elif tmp_max == 0:
    result = N - 2
else:
    result = N - tmp_max - 1
#
print(result)

Buggy submission (verdict: Runtime Error):

def check_other(tmp_i, cur_p, cur_q, cur_x, cur_y, tmp_count):
    for i in range(len(p)):
        if i in tmp_i:
            continue

        tmp_p = p[i][0] - cur_x
        tmp_q = p[i][1] - cur_y

        if tmp_p == cur_p and tmp_q == cur_q:
            tmp_i.append(i)

            tmp_count += 1
            tmp_count = check_other(tmp_i, cur_p, cur_q, p[i][0], p[i][1], tmp_count)


    return tmp_count





if __name__ == "__main__":
    #入力取得
    N = int(input())

    p = []


    for i in range(N):
        l = list(map(int, input().split()))
        p.append(l)

    min_cost = N

    results = []

    counts = []


    for i in range(len(p)):
        tmp_i = [i]
        tmp_count = 0
        if i == 0:
            continue

        tmp_p = p[i][0] - p[0][0]
        tmp_q = p[i][1] - p[0][1]



        tmp_count = check_other(tmp_i, tmp_p, tmp_q, p[i][0], p[i][1], tmp_count)


        counts.append(tmp_count)




tmp_max = max(counts)

if N == 2:
    result = 1
elif tmp_max == 0:
    result = N - 2
else:
    result = N - tmp_max - 1
#
print(result)

Buggy submission (verdict: Runtime Error):
from collections import Counter





if __name__ == "__main__":
    #入力取得
    N = int(input())

    p = []


    results = [[] for i in range(N)]

    for row in results:
        for i in range(N):
            row.append('')

    tmp = []



    for i in range(N):
        l = list(map(int, input().split()))
        p.append(l)


    for i in range(len(p)):
        for j in range(i+1, len(p)):

            if p[i][0] == p[j][0]:
                r = N*N
            else:
                r = (p[i][1]-p[j][1])/(p[i][0]-p[j][0])

            results[i][j] = r

            tmp.append(r)



    counter = Counter(tmp)
    max_r = counter.most_common()[0][0]
    # print(max_r)

    results2 = [0]*N


    for i in range(len(results)):
        for j in range(i+1,len(results)):
            if results[i][j] == max_r:
                results2[i] += 1




    tmp_ans = N - (max(results2) + 1)
    if tmp_ans == 0:
        print(1)
    else:
        print(tmp_ans)