Problem:
 Score : 300 points    Problem Statement There are N balls in a two-dimensional plane. The i -th ball is at coordinates (x_i, y_i) .  We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation:   Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0 . Otherwise, including when this is the first time to do this operation, the cost of this operation is 1 .   Find the minimum total cost required to collect all the balls when we optimally choose p and q .      Constraints  1 \leq N \leq 50  |x_i|, |y_i| \leq 10^9  If i \neq j , x_i \neq x_j or y_i \neq y_j .  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  x_1  y_1  :  x_N  y_N       Output Print the minimum total cost required to collect all the balls.        Sample Input 1 2
1 1
2 2      Sample Output 1 1  If we choose p = 1, q = 1 , we can collect all the balls at a cost of 1 by collecting them in the order (1, 1) , (2, 2) .       Sample Input 2 3
1 4
4 6
7 8      Sample Output 2 1  If we choose p = -3, q = -2 , we can collect all the balls at a cost of 1 by collecting them in the order (7, 8) , (4, 6) , (1, 4) .       Sample Input 3 4
1 1
1 2
2 1
2 2      Sample Output 3 2

Solution (Python):
import sys

inf = 10 ** 18

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

x = [xi for xi, yi in xy]
y = [yi for xi, yi in xy]

ans = inf
for i in range(N - 1):
    xi, yi = xy[i]
    for j in range(i + 1, N):
        xj, yj = xy[j]
        
        p = xj - xi
        q = yj - yi
        
        ans_tmp = 0
        for n, (xn, yn) in enumerate(xy):
            xm = xn - p
            ym = yn - q
            
            if [xm, ym] not in xy: ans_tmp += 1
        
        
        if ans > ans_tmp: ans = ans_tmp

if N == 1:
    print(1)
else:
    print(ans)

Solution (Python):
n=int(input())
if n==1:
  print(1)
else:
 x=[]
 y=[]
 for i in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)

 distance=[]
 for i in range(n):
  for k in range(n):
   if x[i]!=x[k] or y[i]!=y[k]:
    distance.append([x[i]-x[k],y[i]-y[k]])

 q=[]
 for i in range((n**2-n)):
  q.append(distance.count(distance[i]))

 print(n-max(q))

Solution (Python):
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}
ret = float('inf')
for i in range(n - 1):
    for j in range(i + 1, n):
        p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
        if p == 0 and q == 0:
            continue
        key = (p, q)
        d.setdefault(key, 0)
        d[key] += 1
print(n - (max(d.values()) if d  else 0))

Solution (Python):
N=int(input())
xy = [0]*N

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


ans = N

for i in range(N):
    x0 = xy[i][0]
    y0 = xy[i][1]
    
    for j in range(i+1,N):
        ans_sub = N
        vecx = xy[j][0]-x0
        vecy = xy[j][1]-y0
        
        for z in range(N):
            if [xy[z][0]+vecx,xy[z][1]+vecy] in xy:
                ans_sub -= 1
        
        if ans_sub < ans:
            ans = ans_sub

print(ans)

Solution (Python):
import sys
import collections

def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    x = [list(map(int, input().split())) for _ in range(n)]

    if n == 1:
        print(1)
    else:
        dist = [(x[j][0] - x[i][0], x[j][1] - x[i][1]) for j in range(n) for i in range(n)]
        c = collections.Counter(dist)
        ans = c.most_common()
        print(n - ans[1][1])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict, Counter
import bisect

sys.setrecursionlimit(10000000)

n = SI()
xy = [(0,0) for _ in range(n)]
div = defaultdict(int)
for i in range(n):
    x, y = LI()
    xy[i] = (x, y)
if n==1:
    print(1)
else:
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            else:
                div["{}_{}".format(xy[i][0] - xy[j][0], xy[i][1]- xy[j][1])] += 1

    max_ = max(div.values())
    print(n - max_)

Solution (Python):
n = int(input())
xy = []
lili = []
for i in range(n):
    x,y = map(int,input().split())
    xy.append([x,y])
for a in xy:
    for b in xy:
        aa = a[0]-b[0]
        bb = a[1]-b[1]
        if not (aa == 0 and bb == 0):
            lili.append([aa,bb])

kyoutuu = 0
for y in lili:
    if lili.count(y) > kyoutuu:
        kyoutuu = lili.count(y)

print(n-kyoutuu)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from itertools import product
from collections import Counter

def main():
    N = II()
    if N == 1:
        return 1
    XY = []
    for _ in range(N):
        XY.append(LI())
    cnt = Counter()
    for p0, p1 in product(XY, repeat=2):
        dx, dy = p1[0] - p0[0], p1[1] - p0[1]
        if dx != 0 or dy != 0:
            cnt[(dx, dy)] += 1
    ans = N - max(cnt.values())
    return ans

print(main())

Solution (Python):

import numpy as np
from collections import Counter
ls_x = []
ls_y = []
diff = []
N = int(input())
for n in range(N):
    x,y = map(int,input().split())
    for i in range(len(ls_x)):
        diff.append(str((ls_x[i] - x))+"_"+str((ls_y[i] - y)))
        diff.append(str(-(ls_x[i] - x))+"_"+str(-(ls_y[i] - y)))
    ls_x.append(x)
    ls_y.append(y)
if N == 1:
    print (1)
    exit()
cnt = Counter(diff)

print (N-cnt.most_common(1)[0][1])

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
xys = []
for i in range(n):
    (x,y) = words(int)
    xys.append((x,y))

min_score = -1
for i in range(n):
    xy1 = xys[i]
    for j in range(i,n):
        a = set(xys)
        xy2 = xys[j]
        p = xy1[0] - xy2[0]
        q = xy1[1] - xy2[1]
        score = 0
        while len(a) > 0:
            score += 1
            (x,y) = a.pop()
            xup = x + p
            yup = y + q
            while (xup,yup) in a:
                a.remove((xup,yup))
                xup += p
                yup += q
            xdn = x - p
            ydn = y - q
            while (xdn,ydn) in a:
                a.remove((xdn,ydn))
                xdn -= p
                ydn -= q
        if min_score == -1:
            min_score = score
        else:
            min_score = min(min_score,score)
print(min_score)

Solution (Python):
n=int(input())
if n==1:
    print(1)
    exit()
x=[0]*n
y=[0]*n
for i in range(n):
    x[i],y[i]=map(int,input().split())

from collections import Counter
cnt = Counter()
    
for i in range(n):
    for j in range(n):
        if i!=j:
            cnt[str((x[j]-x[i],y[j]-y[i]))]+=1

print(n-cnt.most_common()[0][1])

Solution (Python):
n = int(input()) 
X = [[int(i) for i in input().split()] for i in range(n)] 

from collections import Counter
def cal_diff(x1, x2):
    return (x1[0] - x2[0], x1[1] - x2[1])

if n != 1:
  hoge = [cal_diff(x1, x2) for x1 in X for x2 in X if x1 != x2]
  minus = Counter(hoge).most_common(1)[0][1]
  ans = n - minus
  print(ans)
elif n == 1:
  print(1)

Solution (Python):
from itertools import permutations


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

min_cost = n
for xyi, xyj in permutations(xys, 2):
    xi, yi = xyi
    xj, yj = xyj
    p = xj - xi
    q = yj - yi

    cost = n
    for x, y in xys:
        for xx, yy in xys:
            if x == xx - p and y == yy - q:
                cost -= 1
    min_cost = min(min_cost, cost)

print(min_cost)

Solution (Python):
import collections
N = int(input())
A = []
B = []
YHASHNUM = 1000000000
for i in range(N):
    A.append(list(map(int, input().split())))

if N == 1:
    print(1)
else:
    for i in A:
        
        for j in A:
            if i == j:
                continue
            B.append(i[0] - j[0] + (i[1] - j[1]) * YHASHNUM)
    
    C = collections.Counter(B)
    print(N - C.most_common()[0][1])

Solution (Python):
def most_frequent(List):
    counter = 0
    num = List[0]

    for i in List:
        curr_frequency = List.count(i)
        if(curr_frequency> counter):
            counter = curr_frequency
            num = i

    return num

n = int(input())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([x,y])
c = sorted(c)
l = []
for i in range(len(c)-1):
    for j in range(i+1,len(c)):
        l.append([c[j][0]-c[i][0],c[j][1]-c[i][1]])
if(n==1):
    z = most_frequent(c)
else:
    z = most_frequent(l)
l = 1
for i in range(1,len(c)):
    if([c[i][0]-z[0],c[i][1]-z[1]] not in c):
        l+=1
print(l)

Solution (Python):
N = int(input())

balls = [tuple(map(int, input().split())) for i in range(N)]
balls.sort()

pqlist = []
for i in range(len(balls)):
    for j in range(i+1, len(balls)):
        pqlist.append((balls[j][0] - balls[i][0], balls[j][1] - balls[i][1]))

saishouti = 10**9 + 7

ballset = set(balls)
for pq in pqlist:
    count = 0
    for ball in ballset:
        if (ball[0] + pq[0], ball[1] + pq[1]) in ballset:
            count += 1

    saishouti = min(saishouti, len(balls)-count)

if len(balls) == 1:
    print(1)
else:
    print(saishouti)

Solution (Python):
N = int(input())
pos = [list(map(int, input().split())) for i in range(N)]

diffs = {(0,0):0}

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        diff = (pos[j][0] - pos[i][0], pos[j][1] - pos[i][1])
        if diff not in diffs:
            diffs[diff] = 0
        diffs[diff] += 1

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

Solution (Python):
import collections
N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]

diff = []

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            if xy[i][0] > xy[j][0]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] >= xy[j][1]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] < xy[j][1]:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
            else:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))

if N == 1:
    ans = 1
else:
    c = collections.Counter(diff)
    ans = N - sorted(list(c.values()))[-1] // 2
print(ans)

Solution (Python):
def count(xy, pq):

    cnt = 0
    for k in range(n):
        
        for l in range(k+1, n):
            if (xy[l][0] - xy[k][0] == pq[0]) and (xy[l][1] - xy[k][1] == pq[1]):
                cnt += 1
    return cnt
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append([x,y])
if n == 1:
    print(1)
else:
    m = 0
    xy.sort()
    for i in range(n):
        for j in range(i+1, n):
            pq = [xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]]
            if m < count(xy,pq):
                m = count(xy,pq)
    print(n-m)

Solution (Python):
N = int(input())
x = [0]*N
y = [0]*N
L1_dict = dict()
for i in range(N):
    x[i], y[i] = map(int, input().split())
xy = zip(x, y)
xy = sorted(xy, key=lambda x: (x[0], x[1]))
x, y = zip(*xy)
for i in range(N-1):
    for j in range(i, N):
        if i != j:
            x_diff = x[j] - x[i]
            y_diff = y[j] - y[i]
            if (x_diff, y_diff) not in L1_dict:
                L1_dict[(x_diff, y_diff)] = 1
            else:
                L1_dict[(x_diff, y_diff)] = 1 + L1_dict[(x_diff, y_diff)]
if L1_dict:
    M = max(L1_dict.values())
    print(N - M)
else:
    print(N)

Solution (Python):
import collections
N = int(input())
x = [0 for i in range(N)]
for i in range(N):
    x[i] = list(map(int, input().split()))
x.sort(key=lambda x: (x[0],x[1]))
salist = []
if N >= 2:
    for i in range(1,N):
        for k in range(1,N):
            if i >= k:
                lb, mb = x[i-k]
                l, m = x[i]
                salist.append((l-lb,m-mb))
    
    c = collections.Counter(salist)
    print( N - c.most_common()[0][1])
else:
    print(1)

Solution (Python):
N=int(input())
A=[]
for i in range(N):
  x,y=map(int,input().split())
  A.append((x,y))
if N==1:
  print(1)
  exit()
ans=10000000
for k in range(N):
  for j in range(k):
    p=A[k][0]-A[j][0]
    q=A[k][1]-A[j][1]
    c=0
    for s in range(N):
      flag=False
      for t in range(N):
        if A[s][0]-p==A[t][0] and A[s][1]-q==A[t][1]:
          flag=True 
          break
      if not flag:
        c+=1
    ans=min(c,ans)
print(ans)

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

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

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

    xy.sort(key=lambda p: (p[0], p[1]))
    

    cand = defaultdict(lambda: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]
            key = '{},{}'.format(p, q)
            cand[key] += 1
    counter = Counter(cand)
    pq_count = counter.most_common()[0][1]
    
    print(N - pq_count)


if __name__ == '__main__':
    main()

Solution (Python):

import itertools
def combinations(array, choose):
    return list(itertools.combinations(array, choose))

def resolve():
    N = int(input())
    Pos = [list(map(int, input().split(" "))) for i in range(N)]
    Pos = sorted(Pos, key=lambda x: (x[0], x[1]), reverse=True)
    diffs = []
    comb = combinations(Pos, 2)
    for i in range(len(comb)):
        xdiff = comb[i][0][0] - comb[i][1][0]
        ydiff = comb[i][0][1] - comb[i][1][1]
        for d in diffs:
            if d[0] == xdiff and d[1] == ydiff:
                d[2] += 1
                break
        else:
            diffs.append([xdiff, ydiff, 1])
    
    maxcnt = 0
    for d in diffs:
        if maxcnt < d[2]:
            maxcnt = d[2]
    
    print(N-maxcnt)

if '__main__' == __name__:
    resolve()

Solution (Python):
"""
map(int,input().split())

X = input().split()
x = []
for i in range(0,len(X)):
    x.append(X[i])

"""

def search(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

N = int(input())



ball = []

for n in range(N):
    x,y = map(int,input().split(" "))
    ball.append((x,y))

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


pqList = []
pqCount = []
for i in range(0,N):
    for j in range(0,N):
        if i != j:
           i_x = ball[i][0]
           i_y = ball[i][1]
           j_x = ball[j][0]
           j_y = ball[j][1]
           s = search(pqList,(i_x-j_x,i_y-j_y))
           if s != -1 :
               pqCount[s] += 1
           else:
               pqList.append((i_x-j_x,i_y-j_y))
               pqCount.append(1)

print(int(N - (max(pqCount))))

Solution (Python):
N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]

balls.sort()

ans = N
for i in range(N):
    for j in range(i+1, N):
        p, q = balls[j][0]-balls[i][0], balls[j][1]-balls[i][1]
        useds = [False] * N
        num = 0
        for a in range(N):
            if useds[a]: continue
            useds[a] = True
            num += 1
            x, y = balls[a]
            for b in range(a+1, N):
                if useds[b]: continue
                if balls[b] == (x+p, y+q):
                    useds[b] = True
                    x, y = balls[b]
        ans = min(ans, num)

print(ans)

Solution (Python):
N = int(input())
L = sorted([list(map(int,input().split())) for i in range(N)])

D = {}

for i in range(N-1) :
    ax,ay = L[i]
    for j in range(i+1,N) :
        bx,by = L[j]
        
        p = bx-ax
        q = by-ay
        tag = str(p)+str(q)
        if tag not in D :
            D[tag] = 1
        else :
            D[tag] += 1
if N == 1 :
    ans = 1
else :
    ans = N-max(D.values())

print(ans)

Solution (Python):
N = int(input())
XY = sorted([tuple(map(int, input().split())) for _ in range(N)])
PQ = []
for i in range(N-1):
    for j in range(i, N):
        PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1]))
PQ = list(set(PQ))
ans = N
for p, q in PQ:
    tmp1 = 1
    check=[0]*N
    for i in range(N-1):
        if check[i]:
            continue
        else:
            check[i] = 1
            tmp2 = 1
        for j in range(i, N):
            if check[j]:
                continue
            else:
                if XY[j][0] - p == XY[i][0] and XY[j][1] - q == XY[i][1]:
                    check[j] == 1
                    tmp2 = 0
                    break
        tmp1 += tmp2        
    ans = min(ans, tmp1)
print(ans)

Solution (Python):
n = int(input())
xy = []
diff = []
for _ in range(n):
  tmp = list(map(int,input().split()))
  xy.append(tmp)
for i in range(n):
  for j in range(n):
    if j != i:
      tmpd = [ xy[j][0] - xy[i][0] , xy[j][1] - xy[i][1] ]
      flag = 0
      for mxy in diff:
        if mxy[1:] == tmpd:
            flag = 1
            mxy[0] += 1
            break
      if flag == 0:
        diff.append([0]+tmpd)
diff.sort()
diff.reverse()
if n == 1:
  print(1)
else:
  print(n-diff[0][0]-1)

Solution (Python):
import collections
def solve():
  n = int(input())
  queue = []
  queue2 = []
  if n == 1:
    print(1)
    exit()
  for i in range(n):
   x,y = (int(i) for i in input().split())
   queue.append((x,y))
  for i in range(n):
    for j in range(n):
      if i!=j:
        x1,y1 = queue[i]
        x2,y2 = queue[j]
        p = x2-x1
        q = y2-y1
        queue2.append((p,q))
  
  
  c = collections.Counter(queue2)
  ans = n
  print(ans-c.most_common()[0][1])
solve()

Solution (Python):
N = int(input())
X = []
Y = []
for i in range(N):
  x, y = [int(item) for item in input().split()]
  X.append(x)
  Y.append(y)
if N == 1:
  print (1)
else:
  result={}
  maxv = -100
  for i in range(N):
      for j in range(N):
        dx, dy = X[j]-X[i], Y[j]-Y[i]
        if dx > 0 or dy > 0:
          if (dx, dy) not in result:
            result[(dx, dy)] = 1
          else:
            result[(dx, dy)] += 1
          if result[(dx, dy)]>maxv:
            maxv=result[(dx, dy)]
  print (N-maxv)

Solution (Python):
N = int(input())
List=[list(map(int,input().split())) for i in range(N)]
A = []
b =[]
for i in range(N):
    for j in range(i):
        if List[i][0] > List[j][0]:
            a = [List[i][0]-List[j][0],List[i][1]-List[j][1]]
        elif List[i][0] < List[j][0]:
            a = [List[j][0]-List[i][0],List[j][1]-List[i][1]]
        else:
            if List[i][1] > List[j][1]:
                a = [List[i][0]-List[j][0],List[i][1]-List[j][1]]
            elif List[i][1] < List[j][1]:
                a = [List[j][0]-List[i][0],List[j][1]-List[i][1]]
        b.append(A.count(a))
        A.append(a)
if b == []:
    print(1)
else:
    print(N-max(b)-1)

Solution (Python):
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
if N == 1:
    print(1)
    exit()

XY.sort(key=lambda x: x[0])

PQ = {}

for i in range(N):
    x0, y0 = XY[i]
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[j]
        p, q = x0 - x1, y0 - y1
        key = str(p) + ',' + str(q)
        if key in PQ:
            PQ[key] += 1
        else:
            PQ[key] = 1
ansL = PQ.values()
print(N - max(list(ansL)))

Solution (Python):
import sys
def cul(p,q):
    tmp=0
    for i in range(1,N):
        for j in range(i):
            tmpp,tmpq=a[i][0]-a[j][0],a[i][1]-a[j][1]
            if tmpp==p and tmpq==q: tmp+=1
            elif tmpp==-p and tmpq==-q: tmp+=1
    return N-tmp

N=int(input())
if N==1: print(1),sys.exit()
ans=100

a=[list(map(int,input().split())) for i in range(N)]
for i in range(1,N):
    for j in range(i):
        p,q=a[i][0]-a[j][0],a[i][1]-a[j][1]
        ans=min(ans,cul(p,q))
    
print(ans)

Solution (Python):
import itertools


def main():
  n = int(input())
  p = [tuple(map(int, input().split())) for _ in range(n)]
  c = {}

  if n == 1:
    print(1)
    return

  for i, j in itertools.product(range(len(p)), repeat=2):
    if i == j:
      continue

    d = (p[j][0] - p[i][0], p[j][1] - p[i][1])

    if d not in c:
      c[d] = 1
    else:
      c[d] += 1

  print(len(p) - max(c.values()))


if __name__ == '__main__':
  main()

Solution (Python):
from copy import *
from collections import*
n=int(input())
if n==1:
    print(1)
    exit()
p=[list(map(int,input().split()))for i in range(n)]
l=[]
for i in range(n):
    q=deepcopy(p)
    a,b=q.pop(i)

    l.extend([(s-a,t-b)for s,t in q])
print(n-(Counter(l).most_common()[0][1]+1)+1)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7


import collections
import itertools
import operator


class UnionFind:
    def __init__(self, elems=None):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)

        if elems is not None:
            for elem in elems:
                _, _ = self.parent[elem], self.rank[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def are_same(self, x, y):
        return self.find(x) == self.find(y)

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]


def main(): 
    N = II()
    position = []
    for _ in range(N):
        position.append(LI())

    min_ = INF
    import itertools
    for A, B in itertools.combinations(range(N), 2):
        uf = UnionFind(range(N))
        p = position[A][0] - position[B][0]
        q = position[A][1] - position[B][1]
        
        uf.unite(A, B)
        for X, Y in itertools.combinations(range(N), 2):
            if A == X and B == Y:
                continue
            if (p == position[X][0] - position[Y][0] and q == position[X][1] - position[Y][1]) or (p == position[Y][0] - position[X][0] and q == position[Y][1] - position[X][1]):
                uf.unite(X, Y)
        
        min_ = min(min_, len(list(uf.grouper())))
    print(1 if N == 1 else min_)

main()

Solution (Python):
import collections
n=int(input())
xy=[]
for i in range(n):
    xy.append(list(map(int,input().split())))
dif=[]
for i in range(n):
    for k in range(i+1,n):
        dif.append([xy[i][0]-xy[k][0],xy[i][1]-xy[k][1]])
        dif.append([xy[k][0]-xy[i][0],xy[k][1]-xy[i][1]])
for i in range(len(dif)):
    dif[i]=str(dif[i])
c=collections.Counter(dif)
ans=list(c.values())
ans.sort(reverse=True)

if n==1:
    print(1)
else:
    print(n-ans[0])

Solution (Python):
import sys

sys.setrecursionlimit(10000)
mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y / 2) ** 2 % mod
    else:
        return power(x, y / 2) ** 2 * x % mod


def div(a, b):
    return mul(a, power(b, mod - 2))































































ans = 0
N = int(input())
X = [0 for _ in range(N)]
Y = [0 for _ in range(N)]
for i in range(N):
    X[i], Y[i] = map(int, input().split())

ans = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x = X[i] - X[j]
        y = Y[i] - Y[j]
        ans_loop = 0

        for first in range(N):
            for second in range(N):
                if first == second:
                    continue
                if X[first] == X[second] - x and Y[first] == Y[second] - y:
                    ans_loop += 1
                    break

        ans = max(ans, ans_loop)

print(N-ans)

Solution (Python):



from collections import defaultdict

N = int(input())
X = []
for _ in range(N):
    X.append(list(map(int, input().rstrip().split(' '))))

max_count = 0
d = defaultdict(lambda: defaultdict(int))
for i in range(N):
    for j in range(i+1, N):
        d[X[i][0] - X[j][0]][X[i][1] - X[j][1]] += 1
        max_count = max(max_count, d[X[i][0] - X[j][0]][X[i][1] - X[j][1]])
        d[X[j][0] - X[i][0]][X[j][1] - X[i][1]] += 1
        max_count = max(max_count, d[X[j][0] - X[i][0]][X[j][1] - X[i][1]])
        
print(N - max_count)

Solution (Python):
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]

counter = Counter()
for i in range(N):
    for j in range(i+1, N):
        nxy = xy[i]
        pxy = xy[j]
        counter[(nxy[0]-pxy[0], nxy[1]-pxy[1])] += 1
        counter[(pxy[0]-nxy[0], pxy[1]-nxy[1])] += 1

if N == 1:
    print(1)
else:
    print(N-counter.most_common(1)[0][1])

Solution (Python):
N = int(input())
p = []
for i in range(N):
    x, y = [int(c) for c in input().split()]
    p.append((x,y))

t = {}
for i, pi in enumerate(p):
    for j, pj in enumerate(p):
        if i==j : continue
        
        dx, dy = pi[0] - pj[0], pi[1] - pj[1]
        if (dx, dy) in t:
            t[(dx, dy)] += 1
        else:
            t[(dx, dy)] = 1

if N==1:
    print(1)
else:
    print(N-max([t[k] for k in t]))

Solution (Python):
import collections

N = int(input())

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

if N >= 2:
    relations = []
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            else:
                relations.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))
    
    relations = collections.Counter(relations)
    most_common = relations.most_common()[0][1]
    print(N-most_common)
else:
    print(1)

Solution (Python):
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

N = int(input())
xy = []
field = defaultdict(int)
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
    field[(x,y)] = 1
xy.sort()

pq = set()
for i in range(N):
    for j in range(i+1,N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        p, q = x2-x1, y2-y1
        pq.add((p,q))

ans = N
for p, q in pq:
    removed = defaultdict(int)
    cost = 0
    for x, y in xy:
        if removed[(x,y)]:
            continue
        else:
            removed[(x,y)] = 1
            cost += 1
            while True:
                x += p
                y += q
                if field[(x,y)]:
                    removed[(x,y)] = 1
                else:
                    break
    if cost < ans:
        ans = cost

print(ans)

Solution (Python):
N = int(input())
m = []
for _ in range(N):
    x, y = map(int, input().split())
    m.append((x, y))
s = set(m)

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

ans = float("inf")
for i in range(N):
    x0, y0 = m[i]
    for j in range(N):
        if i == j:
            continue
        x1, y1 = m[j]
        p = x1 - x0
        q = y1 - y0
        c = 0
        for k in range(N):
            x, y = m[k]
            if (x + p, y + q) not in s:
                c += 1
        ans = min(ans, c)
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op



inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    n = get_int()
    if n == 1:
        print(1)
        return
    X, Y = get_data(n, [int, int])
    vecs = Counter()
    for i in range(n):
        for j in range(i+1, n):
            if X[i] > X[j] or (X[i] == X[j] and Y[i] > Y[j]):
                vecs[(X[i]-X[j], Y[i]-Y[j])] += 1
            else:
                vecs[(X[j]-X[i], Y[j]-Y[i])] += 1
    print(n-vecs.most_common()[0][1])
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Solution (Python):
N = input()
N = int(N)
s = [[ int(i) for i in input().split()] for i in range(N)]
hoge = []
import collections

for i in s:
    for k in s:
        if k != i:
            hoge1 = (i[0] - k[0],i[1] - k[1])
            if hoge1[0] <= 0:
                hoge1 = (k[0] - i[0],k[1] - i[1])
            if hoge1[0] == 0 and hoge1[1] <= 0:
                hoge1 = (k[0] - i[0],i[1] - k[1])
            hoge.append(hoge1)
if len(hoge) >= 1:
	c = collections.Counter(hoge)
	print(N - c.most_common()[0][1] // 2)
else:
    print(1)

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

d = {(-1, -1): 0}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        x3, y3 = x2-x1, y2-y1
        if x3 < 0 or (x3 == 0 and y3 < 0):
            x3, y3 = -1*x3, -1*y3
        pos = (x3, y3)
        if pos not in d:
            d[pos] = 0
        d[pos] += 1


print(N - max(d.values())//2)

Solution (Python):
n=int(input())
s=[]
d=[]
i=0
while i!=n:
    s=list(map(int,input().split()))
    d.append(s)
    i+=1

i=0
f=[]
s=[]
j=0
while i!=n:
    while j!=n:
        if i!=j:
            f.append(d[i][0]-d[j][0])
            f.append(d[i][1] - d[j][1])
            s.append(f)
            f=[]

        j += 1
    i+=1
    j=0



i=0
f=[]
while i!=len(s):
    f.append(s.count(s[i]))
    i+=1

try:
    print(int(n-max(f)))
except:
    print(1)