qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import defaultdict
n=int(input())
c=[]
for _ in range(n): c.append(list(map(int,input().split())))
dic=defaultdict(int)
for i in range(0,n-1):
    for j in range(i+1,n):
        if c[i][0]>=c[j][0]: temp=(c[i][0]-c[j][0],c[i][1]-c[j][1])
        else: temp=(c[j][0]-c[i][0],c[j][1]-c[i][1])
        dic[temp]+=1
if dict(dic):
    temp=max(dic.values())
    if temp==1: print(n)
    else: print(n-temp)
else: print(1)

Fixed code:
from collections import defaultdict
n=int(input())
c=[]
for _ in range(n): c.append(list(map(int,input().split())))
dic=defaultdict(int)
for i in range(n):
    for j in range(n):
        if i==j: continue
        dic[(c[i][0]-c[j][0],c[i][1]-c[j][1])]+=1
if dict(dic): print(n-max(dic.values()))
else: print(1)
Buggy code:
import itertools

def main():
    N = int(input())
    z = []
    ans = 51
    for i in range(N):
        z.append(tuple(map(int, input().split())))
    z.sort(key=lambda x: x[0])
    for i, j in itertools.combinations(range(N), 2):
        p = z[i][0] - z[j][0]
        q = z[i][1] - z[j][1]
        ans = min(ans, solve(N, z, p, q))
    print(ans)

def solve(N, z, p, q):
    if p < 0:
        p, q = -p, -q
    passlist = set()
    cnt = 0
    for i in range(N):
        if z[i] in passlist:
            continue
        x, y = z[i][0], z[i][1]
        for j in range(N):
            s, t = x-p, y-q
            if (s, t) not in z:
                cnt += 1
                break
            passlist.add((s, t))
            x, y = s, t
    return cnt

if __name__ == "__main__":
    main()


Fixed code:
import itertools

def main():
    N = int(input())
    z = []
    ans = 51
    for i in range(N):
        z.append(tuple(map(int, input().split())))
    z.sort(key=lambda x: x[1])
    z.sort(key=lambda x: x[0], reverse=True)
    if len(z) == 1:
        print(1)
        return
    for i, j in itertools.combinations(range(N), 2):
        p = z[i][0] - z[j][0]
        q = z[i][1] - z[j][1]
        ans = min(ans, solve(N, z, p, q))
    print(ans)

def solve(N, z, p, q):
    passlist = set()
    cnt = 0
    for i in range(N):
        if z[i] in passlist:
            continue
        x, y = z[i][0], z[i][1]
        for j in range(N):
            s, t = x-p, y-q
            if (s, t) not in z:
                cnt += 1
                break
            passlist.add((s, t))
            x, y = s, t
    return cnt

if __name__ == "__main__":
    main()
Buggy code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
x = [LIST() for i in range(n)]
l = list(range(n))
reg = 0

for v in permutations(l, n):
    a = []
    for i in range(1, n):
        a.append((x[v[i]][0]-x[v[i-1]][0], x[v[i]][1]-x[v[i-1]][1]))
    a.sort()
    count = 1
    for j in range(1, n-1):
        if a[j][:] == a[j-1][:]:
            count += 1
            reg = max(reg, count)
        else:
            count = 1

ans = n - reg
print(ans)

Fixed code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
x = [LIST() for i in range(n)]
reg = 0

for i in range(n):
    for j in range(n):
        if i != j:
            p = x[j][0] - x[i][0]
            q = x[j][1] - x[i][1]
            count = 0
            for k in range(n):
                for l in range(n):
                    if x[l][0] - x[k][0] == p  and x[l][1] - x[k][1] ==  q:
                        count += 1
            reg = max(reg, count)

ans = n - reg
print(ans)
Buggy code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
xy=[lnii() for i in range(n)]
xy.sort(key=lambda x:x[0])

ans=n

pq=[]
for i in range(n-1):
  for j in range(1,n):
    t_p=xy[j][0]-xy[i][0]
    t_q=xy[j][1]-xy[i][1]
    pq.append([t_p,t_q])

for p,q in pq:
  cnt=0
  for j in range(n-1):
    for k in range(1,n):
      x1,y1=xy[j]
      x2,y2=xy[k]
      if x2-x1==p and y2-y1==q:
        cnt+=1
  ans=min(ans,ans-cnt)

print(ans)

Fixed code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
xy=[lnii() for i in range(n)]
xy.sort(key=lambda x:x[0])

ans=n

pq=[]
for i in range(n-1):
  for j in range(i+1,n):
    t_p=xy[j][0]-xy[i][0]
    t_q=xy[j][1]-xy[i][1]
    pq.append([t_p,t_q])

for p,q in pq:
  cnt=0
#  for x,y in xy:
#    if [x+p,y+q] in xy:
#      cnt+=1
  for i in range(n):
    for j in range(n):
      if i==j:
        continue
      x1,y1=xy[i]
      x2,y2=xy[j]
      if (x2-x1)==p and (y2-y1)==q:
        cnt+=1
  ans=min(ans,n-cnt)
print(ans)
Buggy code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
xy=[lnii() for i in range(n)]
xy.sort(key=lambda x:x[0])

ans=n

pq=[]
for i in range(n-1):
  for j in range(1,n):
    t_p=xy[j][0]-xy[i][0]
    t_q=xy[j][1]-xy[i][1]
    pq.append([t_p,t_q])

for p,q in pq:
  cnt=0
  for x,y in xy:
    if [x+p,y+q] in xy:
        cnt+=1
  ans=min(ans,n-cnt)

print(ans)

Fixed code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
xy=[lnii() for i in range(n)]
xy.sort(key=lambda x:x[0])

ans=n

pq=[]
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    t_p=xy[j][0]-xy[i][0]
    t_q=xy[j][1]-xy[i][1]
    pq.append([t_p,t_q])

for p,q in pq:
  cnt=0
  for x,y in xy:
    if [x+p,y+q] in xy:
        cnt+=1
  ans=min(ans,n-cnt)

print(ans)
Buggy code:
from collections import defaultdict

n = int(input())
x, y = [0] * n, [0] * n
data = defaultdict(int)
for i in range(n):
    x[i], y[i] = map(int, input().split())

for i in range(n):
    for j in range(n):
        data[x[j] - x[i], y[j] - y[i]] += 1

print(n - max(data.values()))

Fixed code:
from collections import defaultdict

n = int(input())
x, y = [0] * n, [0] * n
data = defaultdict(int)
for i in range(n):
    x[i], y[i] = map(int, input().split())

if n == 1:
    print(1)
    exit()
for i in range(n):
    for j in range(n):
        if i != j:
            data[x[j] - x[i], y[j] - y[i]] += 1

print(n - max(data.values()))
Buggy code:
N = int(input())
XYs = [list(map(int, input().split())) for _ in range(N)]

dic = {}
tmp = 0

for i in range(N):
  for j in range(N):
    if i == j:
      continue
    p = XYs[j][0] - XYs[i][0]
    q = XYs[j][1] - XYs[i][1]

    if "{}_{}".format(p,q) not in dic:
      dic["{}_{}".format(p,q)] = 1
    else:
      dic["{}_{}".format(p,q)] += 1
      
for k in dic:
  if tmp < dic[k]:
    tmp = dic[k]

print(dic)
print(N-tmp)

Fixed code:
N = int(input())
XYs = [list(map(int, input().split())) for _ in range(N)]

dic = {}
tmp = 0

for i in range(N):
  for j in range(N):
    if i == j:
      continue
    p = XYs[j][0] - XYs[i][0]
    q = XYs[j][1] - XYs[i][1]

    if "{}_{}".format(p,q) not in dic:
      dic["{}_{}".format(p,q)] = 1
    else:
      dic["{}_{}".format(p,q)] += 1
      
for k in dic:
  if tmp < dic[k]:
    tmp = dic[k]

print(N-tmp)
Buggy code:
import math

n=int(input())

XY=[]

for i in range(n):
    x,y=map(int,input().split())
    XY.append([x,y])

v=[]

for i in range(n):
    for j in range(n):
        if j!=i and [XY[i][0]-XY[j][0],XY[i][1]-XY[j][1]] not in v:
            v.append([XY[i][0]-XY[j][0],XY[i][1]-XY[j][1]])

print(v)

c=0
for vx,vy in v:
    cv=0
    for i in range(n):
        for j in range(n):
            if j!=i and [XY[i][0]-XY[j][0],XY[i][1]-XY[j][1]]==[vx,vy]:
                cv+=1
    c=max(cv,c)

print(n-c)

Fixed code:
import math

n=int(input())

XY=[]

for i in range(n):
    x,y=map(int,input().split())
    XY.append([x,y])

v=[]

for i in range(n):
    for j in range(n):
        if j!=i:
            v.append([XY[i][0]-XY[j][0],XY[i][1]-XY[j][1]])


c=0
for vx,vy in v:
    cv=0
    for i in range(n):
        for j in range(n):
            if j!=i and [XY[i][0]-XY[j][0],XY[i][1]-XY[j][1]]==[vx,vy]:
                cv+=1
    c=max(cv,c)

print(n-c)
Buggy code:
from itertools import combinations
from collections import Counter


def main():
    n = int(input())
    if n == 1:
        print(1)

    XY = [list(map(int, input().split())) for _ in range(n)]
    d = []
    for A, B in combinations(XY, 2):
        x1, y1 = A[0], A[1]
        x2, y2 = B[0], B[1]
        p, q = x2 - x1, y2 - y1
        d.append((p,q))
    # print(d)
    # print(Counter(d))

    C = Counter(d)
    ans = 0
    for v in C.values():
        ans = max(ans, v)
    print(ans)

if __name__ == "__main__":
    main()


Fixed code:
from itertools import combinations
from collections import Counter


def main():
    n = int(input())
    if n == 1:
        print(1)
        exit()

    XY = [list(map(int, input().split())) for _ in range(n)]
    d = []
    for A, B in combinations(XY, 2):
        x1, y1 = A[0], A[1]
        x2, y2 = B[0], B[1]
        p, q = x2 - x1, y2 - y1
        d.append((p, q))
        d.append((-p, -q))
    # print(d)
    # print(Counter(d))

    C = Counter(d)
    ans = 0
    for v in C.values():
        ans = max(ans, v)
    print(n - ans)


if __name__ == "__main__":
    main()
Buggy code:
N=int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  x[i],y[i] = map(int,input().split() )
d=dict()

maxi=0
for i in range(N-1):
  for j in range(i+1,N):
    if (x[j]-x[i],y[j]-y[i]) not in d:
      d[ (x[j]-x[i],y[j]-y[i]) ] =1
    else:
      d[ (x[j]-x[i],y[j]-y[i]) ] +=1

#print(d)
for p in d:
  maxi=max(maxi,d[p])
if maxi==1:
  maxi=0
ans= (N-1-maxi)+1
print(ans)


Fixed code:
N=int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  x[i],y[i] = map(int,input().split() )
d=dict()

maxi=0
for i in range(N-1):
  for j in range(i+1,N):
    if (x[j]-x[i],y[j]-y[i]) not in d:
      d[ (x[j]-x[i],y[j]-y[i]) ] =1
      d[ (x[i]-x[j],y[i]-y[j]) ] =1
    else:
      d[ (x[j]-x[i],y[j]-y[i]) ] +=1
      d[ (x[i]-x[j],y[i]-y[j]) ] +=1
#print(d)      

for p in d:
  maxi=max(maxi,d[p])
ans= (N-1-maxi)+1
print(ans)
Buggy code:
n = int(input())
pos = []
for _ in range(n):
    p = list(map(int, input().split()))
    pos.append(p)

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dpos = [pos[i][0] - pos[j][0], pos[i][1] - pos[j][1]]
        cnt = 0
        for k in range(n - 1):
            for l in range(k+1, n):
                tmp = [pos[k][0] - pos[l][0], pos[k][1] - pos[l][1]]
                if dpos[0] == tmp[0] and dpos[1] == tmp[1]:
                    cnt += 1
        print(dpos, cnt)
        ans = max(cnt, ans)

print(n-ans)


Fixed code:
n = int(input())
pos = []
for _ in range(n):
    p = list(map(int, input().split()))
    pos.append(p)

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dpos = [pos[i][0] - pos[j][0], pos[i][1] - pos[j][1]]
        cnt = 0
        for k in range(n):
            for l in range(n):
                if k == l:
                    continue
                tmp = [pos[k][0] - pos[l][0], pos[k][1] - pos[l][1]]
                if dpos[0] == tmp[0] and dpos[1] == tmp[1]:
                    cnt += 1
        ans = max(cnt, ans)

print(n-ans)
Buggy code:
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
x={}
for i in l:
    for j in l:
        if i!=j:
            t=(i[0]-j[0],i[1]-j[1])
            if t in x:
                x[t]+=1
            else:
                x[t]=1
print(max(x.values()))

Fixed code:
n=int(input())
l=[]
if n==1:
    print(1)
    exit()
else:
    for i in range(n):
        x,y=map(int,input().split())
        l.append((x,y))
    x={}
    for i in l:
        for j in l:
            if i!=j:
                t=(i[0]-j[0],i[1]-j[1])
                if t in x:
                    x[t]+=1
                else:
                    x[t]=1
    print(n-max(x.values()))
Buggy code:
n = int(input())
xy = []
for _ in range(n):
    x, y = map(int, input().split())
    xy.append((x, y))
dxdy = {}
for i in range(n-1):
    for j in range(i+1, n):
        dx = xy[i][0] - xy[j][0]
        dy = xy[i][1] - xy[j][1]
        if dx<0:
            dx, dy = -dx, -dy
        if (dx, dy) in dxdy:
            dxdy[(dx, dy)] += 1
        else:
            dxdy[(dx, dy)] = 1
# print(n-max(dxdy.values()))

Fixed code:
n = int(input())
xy = []
for _ in range(n):
    x, y = map(int, input().split())
    xy.append((x, y))
dxdy = {}
if n==1:
    print(1)
    exit()
for i in range(n-1):
    for j in range(i+1, n):
        dx = xy[i][0] - xy[j][0]
        dy = xy[i][1] - xy[j][1]
        if dx<0:
            dx, dy = -dx, -dy
        elif dx==0:
            dx, dy = dx, abs(dy)
        if (dx, dy) in dxdy:
            dxdy[(dx, dy)] += 1
        else:
            dxdy[(dx, dy)] = 1
print(n-max(dxdy.values()))
Buggy code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    N = int(input())
    if N == 1:
        print(1)
        exit()
    XY = [0] * N
    for i, (x, y) in enumerate([[int(x) for x in input().strip().split()] for _ in range(N)]):
        XY[i] = (x, y)
    XY.sort(key=lambda x:(x[0], x[1]))
    print(XY)
    for i in range(len(XY)-1):
        print(XY[i+1][0]-XY[i][0], XY[i+1][1]-XY[i][1])
    dic = defaultdict(int)
    for d in range(1, N):
        for i in range(N-d):
            dic[(XY[i+d][0]-XY[i][0], XY[i+d][1]-XY[i][1])] += 1
            dic[(XY[i][0]-XY[i+d][0], XY[i][1]-XY[i+d][1])] += 1

    print(N-max(dic.values()))

if __name__ == '__main__':
    main()

Fixed code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    N = int(input())
    if N == 1:
        print(1)
        exit()
    XY = [0] * N
    for i, (x, y) in enumerate([[int(x) for x in input().strip().split()] for _ in range(N)]):
        XY[i] = (x, y)
    XY.sort(key=lambda x:(x[0], x[1]))

    dic = defaultdict(int)
    for d in range(1, N):
        for i in range(N-d):
            dic[(XY[i+d][0]-XY[i][0], XY[i+d][1]-XY[i][1])] += 1
            dic[(XY[i][0]-XY[i+d][0], XY[i][1]-XY[i+d][1])] += 1

    print(N-max(dic.values()))

if __name__ == '__main__':
    main()
Buggy code:
def main():
    N = int(input())
    if N == 1:
        print(1)
        return
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))

    d = {}
    for i in range(N):
        tmp = set()
        for j in range(N):
            if i == j:
                continue
            dx = xy[i][0] - xy[j][0]
            dy = xy[i][1] - xy[j][1]

            if (dx, dy) in tmp:
                continue
            if (dx, dy) not in d:
                d[(dx, dy)] = 1
            else:
                d[(dx, dy)] += 1
            tmp.add((dx, dy))

    d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    cnt = d[0][1]
    print(N - cnt)


Fixed code:
def main():
    N = int(input())
    if N == 1:
        print(1)
        return
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))

    d = {}
    for i in range(N):
        tmp = set()
        for j in range(N):
            if i == j:
                continue
            dx = xy[i][0] - xy[j][0]
            dy = xy[i][1] - xy[j][1]

            if (dx, dy) in tmp:
                continue
            if (dx, dy) not in d:
                d[(dx, dy)] = 1
            else:
                d[(dx, dy)] += 1
            tmp.add((dx, dy))

    d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    cnt = d[0][1]
    print(N - cnt)

main()
Buggy code:
import collections
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]

count={}
ans=0
for i in range(n):
    for j in range(i+1,n):
        x=xy[i][0]-xy[j][0]
        y=xy[i][1]-xy[j][1]
        if (x,y) in count:
            count[(x,y)]+-1
        else:
            count[(x,y)]=1

for v in count.values():
    ans=max(ans,v)
print(n-ans)

Fixed code:
import collections
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
xy.sort()
count={}
ans=0
for i in range(n):
    for j in range(i+1,n):
   #     print(i,j)
        x=xy[i][0]-xy[j][0]
        y=xy[i][1]-xy[j][1]
        if (x,y) in count:
            count[x,y]+=1
        else:
            count[x,y]=1
#print(count)
for v in count.values():
    ans=max(ans,v)
print(n-ans)
Buggy code:
n = int(input())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
dif = dict()
data.sort()
for i in range(n):
    for j in range(i+1, n):
        x = data[i][0] - data[j][0]
        y = data[i][1] - data[j][1]
        if (x,y) in dif:
            dif[(x,y)] += 1
        else:
            dif[(x,y)] = 1
print(dif)
print(n - max([dif[i] for i in dif.keys()]))
        
        



Fixed code:
n = int(input())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
dif = dict()
data.sort()
for i in range(n):
    for j in range(i+1, n):
        x = data[i][0] - data[j][0]
        y = data[i][1] - data[j][1]
        if (x,y) in dif:
            dif[(x,y)] += 1
        else:
            dif[(x,y)] = 1
if len(dif.keys()) == 0:
    print(n)
    exit()
print(n - max([dif[i] for i in dif.keys()]))
Buggy code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

vectors = set()
for i in range(n-1):
    for j in range(i+1, n):
        xi, yi = xy[i]
        xj, yj = xy[j]
        if xj-xi == 0 or yj-yi == 0:
            continue
        unit_vector = (xj-xi, yj-yi)
        vectors |= {unit_vector}
ans = n
for vector in vectors:
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            xi, yi = xy[i]
            xj, yj = xy[j]
            if vector == (xj-xi, yj-yi):
                cnt += 1
    ans = min(ans, n-cnt)
print(ans)


Fixed code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
vectors = set()
for i in range(n-1):
    for j in range(i+1, n):
        xi, yi = xy[i]
        xj, yj = xy[j]
        if xj-xi == 0 and yj-yi == 0:
            continue
        unit_vector = (xj-xi, yj-yi)
        vectors |= {unit_vector}
ans = n
for vector in vectors:
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            xi, yi = xy[i]
            xj, yj = xy[j]
            if vector == (xj-xi, yj-yi):
                cnt += 1
    ans = min(ans, n-cnt)
print(ans)
Buggy code:
from itertools import combinations
n = int(input())
pos = []
for i in range(n):
  pos.append(tuple(map(int,input().split())))
ans = 1e100
def cost(p,q):
  ret = 0
  for i,j in pos:
    ret += 1 - ((i+p,j+q) in pos)
  return ret
for a,b in combinations(pos, 2):
  ans = max(ans, cost(a[0]-b[0],a[1]-b[1]))
print(ans)


Fixed code:
from itertools import combinations
n = int(input())
if n == 1:
  print(1)
  exit(0)
pos = []
for i in range(n):
  pos.append(tuple(map(int,input().split())))
ans = 1e100
def cost(p,q):
  ret = 0
  for i,j in pos:
    ret += 1 - ((i+p,j+q) in pos)
  return ret
for a,b in combinations(pos, 2):
  ans = min(ans, cost(a[0]-b[0],a[1]-b[1]))
print(ans)
Buggy code:
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
s_xy = set(xy)

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        ix, iy = xy[i]
        jx, jy = xy[j]
        p, q = jx - jy, jy - jx
        tc = sum((x-p,y-q) in s_xy for x, y in s_xy)

        count = max(count, tc)
            
print(n-count)

Fixed code:
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
s_xy = set(xy)

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        ix, iy = xy[i]
        jx, jy = xy[j]
        p, q = jx - ix, jy - iy
        tc = sum((x-p,y-q) in xy for x, y in s_xy)

        count = max(count, tc)

print(n-count)
Buggy code:
N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]

li = {}
for i in range(N):
    for j in range(N):
        if i!=j:
            continue

        x1,y1 = XY[i][0],XY[i][1]
        x2,y2 = XY[j][0],XY[j][1]

        mm1 = x2-x1
        mm2 = y2-y1
        if mm1<0 and mm2<0:
            mm1 *= -1
            mm2 *= -1
        PQ = (mm1, mm2)

        if PQ in li:
            li[PQ] += 1
        else:
            li[PQ] = 1

mm = 0
for i in li:
    mm = max(mm,li[i])
print(N-mm)

Fixed code:
N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]

li = {}
for i in range(N):
    for j in range(N):
        if i==j:
            continue

        x1,y1 = XY[i][0],XY[i][1]
        x2,y2 = XY[j][0],XY[j][1]

        mm1 = x2-x1
        mm2 = y2-y1
        # if mm1<0 and mm2<0:
        #     mm1 *= -1
        #     mm2 *= -1
        PQ = (mm1, mm2)

        if PQ in li:
            li[PQ] += 1
        else:
            li[PQ] = 1

mm = 0
for i in li:
    mm = max(mm,li[i])
print(N-mm)
Buggy code:
from collections import Counter
n= int(input())
xy=[[int(x) for x in input().split()] for _ in range(n)]
gr = [[[0,0]for _ in range(n)]for _ in range(n)]
for i in range(n):
  a,b = xy[i]
  for j in range(n):
    gr[i][j] = [xy[j][0]-a,xy[j][1]-b]
gr1 = []
for i in gr:
  for j in i:
    gr1.append(tuple(j))
#print(gr1)
c = Counter(gr1)
l,f = c.most_common()[0]
if l!=(0,0):
  print(n-f)

Fixed code:
from collections import Counter
n= int(input())
if n==1:
  print(1)
  exit()
xy=[[int(x) for x in input().split()] for _ in range(n)]
gr = [[[0,0]for _ in range(n)]for _ in range(n)]
for i in range(n):
  a,b = xy[i]
  for j in range(n):
    gr[i][j] = [xy[j][0]-a,xy[j][1]-b]
gr1 = []
for i in gr:
  for j in i:
    gr1.append(tuple(j))
#print(gr1)
c = Counter(gr1)
l,f = c.most_common()[0]
if l!=(0,0):
  print(n-f)
else:
  l,f = c.most_common()[1]
  print(n-f)
Buggy code:
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(input())
    pos = [list(map(int,input().split())) for _ in range(N)]
    if N == 1:
        print(1)
    else:
        d = defaultdict(int)
        for i in range(N):
            for j in range(i+1,N):
                slope = (pos[i][0]-pos[j][0],pos[i][1]-pos[j][1])
                if slope[0]*slope[1] != 0:
                    d[slope] += 1
        if len(d) == 0:
            print(N)
        else:
            print(N-max(d.values()))

if __name__ == "__main__":
    main()

Fixed code:
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(input())
    pos = [list(map(int,input().split())) for _ in range(N)]
    if N == 1:
        print(1)
    else:
        d = defaultdict(int)
        for i in range(N):
            for j in range(N):
                slope = (pos[i][0]-pos[j][0],pos[i][1]-pos[j][1])
                if slope[0] != 0 or slope[1] != 0:
                    d[slope] += 1
        if len(d) == 0:
            print(N)
        else:
            print(N-max(d.values()))

if __name__ == "__main__":
    main()