qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import Counter
n=int(input())
b=[tuple(map(int,input().split())) for _ in range(n)]
r=[(x[0]-y[0],x[1]-y[1]) for x in b for y in b if x!=y]
c=Counter(r).most_commom(1)
print(n-c[0][1] if c else n)

Fixed code:
from collections import Counter
n=int(input())
b=[tuple(map(int,input().split())) for _ in range(n)]
r=[(x[0]-y[0],x[1]-y[1]) for x in b for y in b if x!=y]
c=Counter(r).most_common(1)
print(n-c[0][1] if c else n)
Buggy code:
import collections
import sys

N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]

if N == 1:
    print(1)
    sys.exit()

pq = []
for i in range(N):
    for j in range(N):
        if i != j:
            pq.append((xy[i][0]-xy[j][0], xy[i][1]-xy[j][1]))
print(pq)
pqc = collections.Counter(pq)
x = pqc.most_common()[0][1]
print(N-x)



Fixed code:
import collections
import sys

N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]

if N == 1:
    print(1)
    sys.exit()

pq = []
for i in range(N):
    for j in range(N):
        if i != j:
            pq.append((xy[i][0]-xy[j][0], xy[i][1]-xy[j][1]))
#print(pq)
pqc = collections.Counter(pq)
x = pqc.most_common()[0][1]
print(N-x)
Buggy code:
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
pq = []
for i in range(n):
	for j in range(i + 1, n):
		xi, yi = xy[i]
		xj, yj = xy[j]
		if xi==xj or yi==yj:
			continue
		pq.append((xi - xj, yi - yj))
ans = 1e9
for p, q in pq:
	cost = 0
	for x, y in xy:
		if (x + p, y + q) in xy:
			pass
		else:
			cost += 1
	ans = min(ans, cost)
print(ans)


Fixed code:
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
pq = []
for i in range(n):
	for j in range(n):
		if i==j:
			continue
		xi, yi = xy[i]
		xj, yj = xy[j]
		pq.append((xi - xj, yi - yj))
ans = 1e9 if n>1 else 1
for p, q in pq:
	cost = 0
	for x, y in xy:
		if (x + p, y + q) in xy:
			pass
		else:
			cost += 1
	ans = min(ans, cost)
print(ans)
Buggy code:
from collections import Counter
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]

if N==1:
  print(1)
  exit()

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

print(Counter(map(lambda x:x[0]*10**10+x[1],pq)).most_common())
print(N-Counter(map(lambda x:x[0]*10**10+x[1],pq)).most_common()[0][1])

Fixed code:
from collections import Counter
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]
xy.sort()

if N==1:
  print(1)
  exit()

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

print(N-Counter(map(lambda x:x[0]*10**10+x[1],pq)).most_common()[0][1])
Buggy code:
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i],y[i] = map(int,input().split())

memo = {}

for i in range(N-1):
    for j in range(i+1,N):
        dx = x[j] - x[i]
        dy = y[j] - y[i]
        if ((dx,dy) in memo) or ((-dx,-dy) in memo):
            memo[(dx,dy)] += 1
        else:
            #memo[(dx,dy)] = 1
        print(memo)

M = max(memo.values())

print(N-M)


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

if N == 1:
    print(1)
else:
    memo = {}

    for i in range(N-1):
        for j in range(i+1,N):
            dx = x[j] - x[i]
            dy = y[j] - y[i]
            if (dx,dy) in memo:
                memo[(dx,dy)] += 1
            elif (-dx,-dy) in memo:
                memo[(-dx,-dy)] += 1
            else:
               memo[(dx,dy)] = 1
            #print(memo)

    M = max(memo.values())

    print(N-M)
Buggy code:
#from collections import defaultdict
n = int(input())
di = [list(map(int, input().split(' '))) for _ in range(n)]
#result = {0:0}
md = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            p = di[i][0] - di[j][0]
            q = di[i][1] - di[j][1]
            #result[(p,q)] = result.get((p,q), 0)+1
            md[(p,q)] += 1
#print(result)
#print(n - max(result.values()))
#print(md)
print(n - max(md.values()))

Fixed code:
#from collections import defaultdict
n = int(input())
di = [list(map(int, input().split(' '))) for _ in range(n)]
result = {0:0}
#md = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            p = di[i][0] - di[j][0]
            q = di[i][1] - di[j][1]
            result[(p,q)] = result.get((p,q), 0)+1
            #md[(p,q)] += 1
#print(result)
print(n - max(result.values()))
#print(md)
#print(n - max(md.values()))
Buggy code:
import collections

N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
if N==1:
  print(1)
else:
  arr = sorted(arr,key=lambda x:(x[0],x[1]))
  diff_arr = []
  for j in range(N):
    for k in range(1,N-j):
      diff_arr.append(str(arr[j+k][0]-arr[j][0])+'_'+str(arr[j+k][1]-arr[j][1]))
  print(diff_arr)
  c = collections.Counter(diff_arr)
  print(N-max(c.values()))
  

Fixed code:
import collections

N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
if N==1:
  print(1)
else:
  arr = sorted(arr,key=lambda x:(x[0],x[1]))
  diff_arr = []
  for j in range(N):
    for k in range(1,N-j):
      diff_arr.append(str(arr[j+k][0]-arr[j][0])+'_'+str(arr[j+k][1]-arr[j][1]))
  c = collections.Counter(diff_arr)
  print(N-max(c.values()))
Buggy code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

ans = dict()

if n == 1:
    print(1)
    exit()

for i in range(n):
    for j in range(i+1, n):
        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]
        if ans.get((p, q)) == None:
            ans[(p, q)] = 1
        else:
            ans[(p, q)] += 1
print(ans)
print(list(ans.values()).count(max(ans.values())))

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

ans = dict()

if n == 1:
    print(1)
    exit()

for i in range(n):
    for j in range(n):
        if (i == j):
            continue
        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]
        if ans.get((p, q)) == None:
            ans[(p, q)] = 1
        else:
            ans[(p, q)] += 1
# print(ans)
print(n-max(ans.values()))
Buggy code:
from operator import itemgetter
from collections import defaultdict

big = 10**10
N = int(input())
pt = [[int(x) for x in input().split()] for _ in range(N)]
pt.sort(key = itemgetter(1))
pt.sort(key = itemgetter(0))
di = defaultdict(int)
for i,p0 in enumerate(pt):
    for j,p1 in enumerate(pt):
        if(i>=j):continue
        p,q = p0[0]-p1[0],p0[1]-p1[1]
        di[p*big+q] += 1
maxd = 0
for i in di:
    if(i==0):continue
    maxd = max(di[i],maxd)
print(N-maxd)
print(di)


Fixed code:
from operator import itemgetter
from collections import defaultdict

big = 10**10
N = int(input())
pt = [[int(x) for x in input().split()] for _ in range(N)]
pt.sort(key = itemgetter(1))
pt.sort(key = itemgetter(0))
di = defaultdict(int)
for i,p0 in enumerate(pt):
    for j,p1 in enumerate(pt):
        if(i>=j):continue
        p,q = p0[0]-p1[0],p0[1]-p1[1]
        di[p*big+q] += 1
maxd = 0
for i in di:
    if(i==0):continue
    maxd = max(di[i],maxd)
print(N-maxd)
Buggy code:
def main():

    N = int(input())
    if N == 1: return 1
    if N == 2: return 1

    ball = []
    for _ in range(N):
        x, y = map(int, input().split())
        ball.append((x, y))
    ball.sort()
    

    pq = []
    for i in range(N-1):
        x0, y0 = ball[i]
        for j in range(i+1, N):
            x1, y1 = ball[j]
            pq.append([x1-x0, y1-y0])
    print(pq)

    min_count = N
    for p, q in pq:
        count = 0
        visited = set()
        for b in ball:
            if b not in visited:
                count += 1
                z, w = b[0], b[1]
                while (z, w) in ball:
                    visited.add((z, w))
                    z += p
                    w += q
            # print(visited, count)
        min_count = min(min_count, count)

    return min_count

if __name__ == '__main__':
    print(main())

Fixed code:
def main():

    N = int(input())
    if N == 1: return 1
    if N == 2: return 1

    ball = []
    for _ in range(N):
        x, y = map(int, input().split())
        ball.append((x, y))
    ball.sort()
    

    pq = []
    for i in range(N-1):
        x0, y0 = ball[i]
        for j in range(i+1, N):
            x1, y1 = ball[j]
            pq.append([x1-x0, y1-y0])
    # print(pq)

    min_count = N
    for p, q in pq:
        count = 0
        visited = set()
        for b in ball:
            if b not in visited:
                count += 1
                z, w = b[0], b[1]
                while (z, w) in ball:
                    visited.add((z, w))
                    z += p
                    w += q
            # print(visited, count)
        min_count = min(min_count, count)

    return min_count

if __name__ == '__main__':
    print(main())
Buggy code:
N = int(input())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

ans = 0
for i in range(N):
    rates = {0: 0}
    for j in range(N):
        if i == j:
            continue
        vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
        rates[vector] = rates.get(vector, 0) + 1
    ans = max(ans, max(rates.values()))

print(N - ans)


Fixed code:
N = int(input())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

ans = 1
rates = {0: 0}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
        rates[vector] = rates.get(vector, 0) + 1

print(N - max(rates.values()))
Buggy code:
#XY = [[1,1],[1,2],[2,2],[2,1]]
#N = len(XY)
if N==1:
    print(1)
    exit()
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)

Fixed code:
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
if N==1:
    print(1)
    exit()
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)
Buggy code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
items = list(set(d_list))
s = 0
for item in items:
    c = d_list.count(item)
    if c >= 2 and c > s:
        s = c
print(N - s)

Fixed code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
if N == 1:
    print(1)
else:
    d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
    items = list(set(d_list))
    s = 1
    for item in items:
        c = d_list.count(item)
        if c > s:
            s = c
    print(N - s)
Buggy code:
from collections import Counter
n = int(input())
xy = [tuple([int(_) for _ in input().split()]) for i in range(N)]
if n == 1:
    result = 1
else:
    xy.sort()
    dxy = [(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
           for i in range(N)
           for j in range(i+1, N)]
    cdxy = Counter(dxy)
    result = N - max(cdxy.values())
print(result)

Fixed code:
from collections import Counter
n = int(input())
xy = [tuple([int(_) for _ in input().split()]) for i in range(n)]
if n == 1:
    result = 1
else:
    xy.sort()
    dxy = [(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
           for i in range(n)
           for j in range(i+1, n)]
    cdxy = Counter(dxy)
    result = n - max(cdxy.values())
print(result)
Buggy code:
n = int(input())
if n <= 2:
    print( 1)
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

points.sort()
dictpq = {}
for i in range(n):
    for j in range(i+1,n):
        p = points[i][0] - points[j][0]
        q = points[i][1] - points[j][1]
        if (p,q) in dictpq:
            dictpq[(p,q)] +=1
        else:
            dictpq[(p,q)] =1
print(n-max(dictpq.values()))

Fixed code:
n = int(input())
if n ==1:
    print( 1)
    exit()
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

points.sort()
dictpq = {}
for i in range(n):
    for j in range(i+1,n):
        p = points[i][0] - points[j][0]
        q = points[i][1] - points[j][1]
        if (p,q) in dictpq:
            dictpq[(p,q)] +=1
        else:
            dictpq[(p,q)] =1
print(n-max(dictpq.values()))
Buggy code:
from collections import deque
import statistics
import math
from collections import Counter
N=int(input())
x=[]
y=[]
for a in range(N):
    b,c=(int(x) for x in input().split())
    x.append(b)
    y.append(c)
sa=deque([[0,0]])
if N>1:
    for a in range(N):
        for b in range(N-a-1):
            sx=abs(x[a]-x[a+b+1])
            sy=abs(y[a]-y[a+b+1])
            sa.append([sx,sy])
    sa.remove([0,0])
    ans=[]
    nagasa=len(sa)
    print(sa)
    for a in range(nagasa):
        xx,yy=sa[a]
        ss=sa.count([xx,yy])
        ans.append(ss)
        if len(sa)==0:
            break
    kotae=max(ans)
    print(N-kotae)

else:
    print(1)


Fixed code:
from collections import deque
import statistics
import math
from collections import Counter
N=int(input())
x=[]
y=[]
for a in range(N):
    b,c=(int(xxx) for xxx in input().split())
    x.append(b)
    y.append(c)
sa=deque([[0,0]])
if N>1:
    for a in range(N):
        for b in range(N-a-1):
            sx=x[a]-x[a+b+1]
            sy=y[a]-y[a+b+1]
            sa.append([sx,sy])
    sa.remove([0,0])
    ans=[]
    nagasa=len(sa)
    for a in range(nagasa):
        xx,yy=sa[a]
        ss=sa.count([xx,yy])+sa.count([-xx,-yy])
        ans.append(ss)
    kotae=max(ans)
    print(N-kotae)

else:
    print(1)
Buggy code:
from collections import Counter
from itertools import combinations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

A = Counter()
for (x1, y1), (x2, y2) in combinations(XY, 2):
        if x1 == x2 and y1 == y2:
            continue
        if x1 < x2:
            x1, x2 = x2, x1
            y1, y2 = y2, y1
        A[(x1-x2, y1-y2)] += 1
print(A)
if N == 1:
    print(1)
else:
    print(N - max(A.values())) 

Fixed code:
from collections import Counter
from itertools import combinations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
A = Counter()
for (x1, y1), (x2, y2) in combinations(XY, 2):
    A[(x1-x2, y1-y2)] += 1
if N == 1:
    print(1)
else:
    print(N - max(A.values()))
Buggy code:
b = [
    [int(s) for s in input().split(' ')]
    for i in range(N)
]
b.sort(key=lambda p: p[1])
b.sort(key=lambda p: p[0])
d = {}
d_max = 0
for i in range(N):
    for j in range(i + 1, N):
        p = b[j][0] - b[i][0]
        q = b[j][1] - b[i][1]
        if not p in d:
            d[p] = {}
        d[p][q] = (d[p][q] if q in d[p] else 0) + 1
        d_max = max([d_max, d[p][q]])
print(N - d_max)

Fixed code:
N = int(input())
balls = [
    [int(s) for s in input().split(' ')]
    for i in range(N)
]
balls.sort(key=lambda p: p[1])
balls.sort(key=lambda p: p[0])
d = {}
d_max = 0
for i in range(N):
    for j in range(i + 1, N):
        p = balls[j][0] - balls[i][0]
        q = balls[j][1] - balls[i][1]
        if not p in d:
            d[p] = {}
        d[p][q] = (d[p][q] if q in d[p] else 0) + 1
        d_max = max([d_max, d[p][q]])
print(N - d_max)
Buggy code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
x = [xy[i][0] for i in range(N)]
y = [xy[i][1] for j in range(N)]
if N == 1:
    print(1)
    exit()
else:
    ans = N
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            dx,dy = x[j]-x[i],y[j]-y[i]
            cnt = 0
            for k in range(N):
                for l in range(N):
                    if k == l:
                        continue
                    if dx == x[k]-x[l] and dy == y[k]-y[l]:
                        cnt += 1
            ans = min(ans,N-cnt)

print(ans)

Fixed code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
x = [xy[i][0] for i in range(N)]
y = [xy[i][1] for i in range(N)]
if N == 1:
    print(1)
    exit()
else:
    ans = N
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            dx,dy = x[j]-x[i],y[j]-y[i]
            cnt = 0
            for k in range(N):
                for l in range(N):
                    if k == l:
                        continue
                    if dx == x[k]-x[l] and dy == y[k]-y[l]:
                        cnt += 1
            ans = min(ans,N-cnt)

print(ans)
Buggy code:
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

counter = Counter(((b1[0] - b2[0], b1[1] - b2[1]) for b1 in xy for b2 in xy if b1 != b2))
print(N - (counter.most_common()[0]+[(0,0)])[1])


Fixed code:
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

counter = Counter(((b1[0] - b2[0], b1[1] - b2[1]) for b1 in xy for b2 in xy if b1 != b2))
print(N - (list(counter.most_common())+[(0,0)])[0][1])
Buggy code:
N=int(input())

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

x=[]
y=[]
XY=XY.set()
for X,Y in XY:
    x.append(X)
    y.append(Y)
    
l1=[]
c=0
for i in range(N):
    for j in range(i+1,N):
        a=x[i]-x[j]
        b=y[i]-y[j]
        if a<=0 and b>=0:
            a=-a
            b=-b
        elif a<=0 and b<=0:
            a=-a
            b=-b
        l1.append(str(a)+"_"+str(b))
v=set(l1)
c=[]
for i in v:
    c.append(l1.count(i))
#c = collections.Counter(l1)      
#values, counts = zip(*c.most_common())    
print(N-max(c))


Fixed code:
N=int(input())

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

x=[]
y=[]

for X,Y in XY:
    x.append(X)
    y.append(Y)
    
l1=[]
c=0
for i in range(N):
    for j in range(N):
        if i==j:
            continue;
        a=x[i]-x[j]
        b=y[i]-y[j]
        """
        if a<=0 and b>=0:
            a=-a
            b=-b
        elif a<=0 and b<=0:
            a=-a
            b=-b
        """
        l1.append(str(a)+"_"+str(b))
        #l1.append([a,b])
v=set(l1)
c=[]
for i in v:
    c.append(l1.count(i))
#c = collections.Counter(l1)      
#values, counts = zip(*c.most_common()) 
if c==[]:
    print(1)   
else:
    print(N-max(c))
Buggy code:
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N)]
ans=N-1
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        p=P[i][0]-P[j][0]
        q=P[i][1]-P[j][1]
        if p==0 or q==0:
            continue
        cost=0
        for k in range(N):
            if (P[k][0]-p,P[k][1]-q) not in P:
                cost+=1
        ans=min(ans,cost)
print(ans)

Fixed code:
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N)]
ans=N
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        p=P[i][0]-P[j][0]
        q=P[i][1]-P[j][1]
        cost=0
        for k in range(N):
            if (P[k][0]-p,P[k][1]-q) not in P:
                cost+=1
        ans=min(ans,cost)
print(ans)
Buggy code:
from itertools import combinations

n = int(input())
balls = []
cost = n
for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

for b1, b2 in combinations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    if p != 0 or q != 0:
        sub = 0
        for b3, b4 in permutations(balls, 2):
            dx, dy = b3[0] - b4[0], b3[1] - b4[1]
            if dx == p and dy == q:
                sub += 1
        cost = min(cost, n - sub)

print(max(cost, 1))


Fixed code:
from itertools import combinations

n = int(input())
balls = []
cost = n
for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

for b1, b2 in combinations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    if p != 0 or q != 0:
        sub = 0
        for b3, b4 in combinations(balls, 2):
            dx, dy = b3[0] - b4[0], b3[1] - b4[1]
            if dx == p and dy == q or -dx == p and -dy == q:
                sub += 1
        cost = min(cost, n - sub)

print(max(cost, 1))
Buggy code:
import itertools, collections
N = int(input())
XY = sorted([[int(_) for _ in input().split()] for _ in range(N)])
count = collections.defaultdict(int)
for i, j in itertools.combinations(range(N), 2):
    x1, y1 = XY[i]
    x2, y2 = XY[j]
    print(i, j, XY[i], XY[j])
    count[y2 - y1 + (x2 - x1) * 10**10] += 1
if count:
    print(N - max(count.values()))
else:
    print(1)


Fixed code:
import itertools, collections
N = int(input())
XY = sorted([[int(_) for _ in input().split()] for _ in range(N)])
count = collections.defaultdict(int)
for i, j in itertools.combinations(range(N), 2):
    x1, y1 = XY[i]
    x2, y2 = XY[j]
    count[y2 - y1 + (x2 - x1) * 10**10] += 1
if count:
    print(N - max(count.values()))
else:
    print(1)
Buggy code:
n=int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort()
ans=0
for i in range(n-1):
     for j in range(i+1,n):
            p=xy[j][0]-xy[i][0]
            q=xy[j][1]-xy[i][1]
        mer=0
        for i in range (k):
          if [xy[k][0]+p, xy[k][1]+q] in xy:
            merge += 1
        ans = max(ans, merge)
print(N-ans)
            



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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        p = xy[j][0]-xy[i][0]
        q = xy[j][1]-xy[i][1]
        merge = 0
        for k in range(N):
            if [xy[k][0]+p, xy[k][1]+q] in xy:
                merge += 1
        ans = max(ans, merge)
print(N-ans)
Buggy code:
import collections
N = int(input())
if N == 1:
  print(1)
else if  N == 2:
  print(1)
else:
  ball = [tuple(map(int, input().split())) for _ in range(N)]
  ball.sort(key=lambda x:(x[0], x[1]))
  diff = [tuple((ball[i][0] - ball[i-1][0], ball[i][1] - ball[i-1][1])) for i in range(1,N)]
  c = collections.Counter(diff)
  ans = c.most_common()[0][1]
  print(N - ans)


Fixed code:
import collections
N = int(input())
if N == 1:
  print(1)
elif N == 2:
  print(1)
else:
  ball = [tuple(map(int, input().split())) for _ in range(N)]
  ball.sort(key=lambda x:(x[0], x[1]))
  diff = [tuple((ball[i][0] - ball[j][0], ball[i][1] - ball[j][1])) for i in range(N) for j in range(i + 1, N)]
  c = collections.Counter(diff)
  ans = c.most_common()[0][1]
  print(N - ans)
Buggy code:
n=int(input())
o=[]
for i in range(n):
    x,y=map(int,input().split())
    o.append([x,y])
o.sort()
p2=[]
q2=[]
c=[]
if n==1:
    print(1)
else:
    for i in range(n):
        for j in range(i+1,n):
            p2=o[j][0]-o[i][0]
            q2=o[j][1]-o[i][1]
            c.append(str(p2)+" "+str(q2))
    r=defaultdict(int)
    for f in c:
        r[f]+=1
    p=list(r.values())
    q=max(p)
    print(n-q)

Fixed code:
from collections import defaultdict
n=int(input())
o=[]
for i in range(n):
    x,y=map(int,input().split())
    o.append([x,y])
o.sort()
p2=[]
q2=[]
c=[]
if n==1:
    print(1)
else:
    for i in range(n):
        for j in range(i+1,n):
            p2=o[j][0]-o[i][0]
            q2=o[j][1]-o[i][1]
            c.append(str(p2)+" "+str(q2))
    r=defaultdict(int)
    for f in c:
        r[f]+=1
    p=list(r.values())
    q=max(p)
    print(n-q)