Problem p03006 (python)

Fixed submission:

N = int(input())
xy = []

for i in range(N):

    newxy = list(map(int,input().split()))
    xy.append(newxy)

ans = -1
now = 0

for i in range(N):

    for j in range(i):

        now = 0

        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]


        #print ("p:",p,"q:",q)
        

        xydic = {}

        for k in xy:

            if str(k) in xydic:

                continue
                #print (k,"はすでにxydicに含まれています！")

            else:

                now += 1

                xydic[str(k)] = 1

                #print(k,"をxydicに始点として含めました")

                plbul = True

                cnt = 1
                while plbul:

                    if [ k[0] + cnt * p , k[1] + cnt * q ] in xy :

                        xydic [str([k[0] + cnt * p , k[1] + cnt * q])] = 1
                        #print ([k[0] + cnt * p , k[1] + cnt * q],"を+でxydicに含めました")
                        cnt += 1

                    else:
                        plbul = False

                cnt = -1

                plbul = True
                
                while plbul:

                    if [ k[0] + cnt * p , k[1] + cnt * q ] in xy :

                        xydic [str([k[0] + cnt * p , k[1] + cnt * q])] = 1
                        #print ([k[0] + cnt * p , k[1] + cnt * q] ,"を-でxydicに含めました" )
                        cnt -= 1

                    else:
                        plbul = False

                #print ("now",now)

                                
        if now < ans or ans < 0:
            ans = now
            #print (xydic)

if N == 1:
    ans = 1

print (ans)

Buggy submission (verdict: Runtime Error):

N = int(input())
p = []
dic = {}
sameX = {}
allNum = []

for i in range(N):

    x,y = map(int,input().split())

    p.append([x,y])

    allNum.append(i)


for i in range(N):

    for j in range(i):

        ji = [j,i]
        

        if p[j][0] - p[i][0] != 0:

            a = ( p[j][1] - p[i][1] ) / ( p[j][0] - p[i][0] )
            b = p[j][1] - ( a * p[j][1] )

            if a == -0.0:
                a = 0.0
            
            ab = [a,b]

            if ( str (ab) )  in dic:
                dic[ str (ab) ].append(ji)

            else:
                dic[ str(ab) ] = [ji]

        elif p[j][0] - p[i][0] == 0:

            if p[j][0] in sameX:
                sameX[ p[j][0] ].append(ji)
            else:
                sameX[ p[j][0] ] = [ji]
            

#print  (dic,sameX)
        

DorS = 0
maxi = 0
keys = ""
ans = 0

while len(allNum) > 0:

    DorS = 0
    maxi = 0
    keys = ""

    for i in dic:
        
        eable = {}
        
        for j in dic[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            
                

        if len(eable) > maxi:

            
            DorS = 0
            maxi = len(dic[i])
            keys = i

    for i in sameX:

        eable = {}

        for j in sameX[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            

        if len(eable) > maxi:

            DorS = 1
            maxi = len(sameX[i])
            keys = i


    if DorS == 0:

        delPs = dic[keys]
        del dic[keys]

    else:

        delPs = sameX[keys]
        del sameX[keys]


    #print (delPs)

    rmFlag = False

    for i in delPs:

        if i[0] in allNum :
            allNum.remove(i[0])
            rmFlag = True

        if i[1] in allNum :
            allNum.remove(i[1])
            rmFlag = True

    if rmFlag :
        ans += 1

    #print (allNum)

        
print (ans)

Buggy submission (verdict: Runtime Error):

N = int(input())
p = []
dic = {}
sameX = {}
allNum = []

for i in range(N):

    x,y = map(int,input().split())

    p.append([x,y])

    allNum.append(i)


for i in range(N):

    for j in range(i):

        ji = [j,i]
        

        if p[j][0] - p[i][0] != 0:

            a = ( p[j][1] - p[i][1] ) / ( p[j][0] - p[i][0] )
            b = p[j][1] - ( a * p[j][1] )

            if a == -0.0:
                a = 0.0
            
            ab = [a,b]

            if ( str (ab) )  in dic:
                dic[ str (ab) ].append(ji)

            else:
                dic[ str(ab) ] = [ji]

        elif p[j][0] - p[i][0] == 0:

            if p[j][0] in sameX:
                sameX[ p[j][0] ].append(ji)
            else:
                sameX[ p[j][0] ] = [ji]
            

#print  (dic,sameX)
        

DorS = 0
maxi = 0
keys = ""
ans = 0

while len(allNum) > 0:

    DorS = 0
    maxi = 0
    keys = ""

    for i in dic:
        
        eable = {}
        
        for j in dic[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            
                

        if len(eable) > maxi:

            
            DorS = 0
            maxi = len(dic[i])
            keys = i

    for i in sameX:

        eable = {}

        for j in sameX[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            

        if len(eable) > maxi:

            DorS = 1
            maxi = len(sameX[i])
            keys = i


    if DorS == 0:

        delPs = dic[keys]
        del dic[keys]

    else:

        delPs = sameX[keys]
        del sameX[keys]


    #print (delPs)

    rmFlag = False

    for i in delPs:

        if i[0] in allNum :
            allNum.remove(i[0])
            rmFlag = True

        if i[1] in allNum :
            allNum.remove(i[1])
            rmFlag = True

    if rmFlag :
        ans += 1

    #print (allNum)

        
print (ans)