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):
n=int(input())
l=[]
if n==1:
  print(1)
else:
  for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])

  dic={}
  for i in range(n):
    for j in range(n):
      if i==j:
        continue
      dx,dy = l[j][0]-l[i][0],l[j][1]-l[i][1]
      if (dx,dy) not in dic:
        dic[dx,dy]=1
      else:
        dic[dx,dy]+=1

  dic=sorted(dic.items(),key=lambda x:x[1],reverse=True)
  print(n-dic[0][1])

Solution (Python):
import sys, math, re
from itertools import accumulate
sys.setrecursionlimit(10**9)

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    if N == 1:
        print(1)
        return
        
    x, y = i2(N)
    d = {}

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

            pair = (x[i]-x[j], y[i]-y[j])
            if not pair in d:
                d[pair] = 0
            
            d[pair] += 1

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


if __name__ == "__main__":
    main()

Solution (Python):
import itertools
n = int(input())
xy = []
for i in range(n):
  x,y = map(int, input().split())
  xy.append([x,y])

a={}
for v in itertools.combinations(xy,2):
  z = list(v)
  z.sort()
  x = z[1][0]-z[0][0]
  y = z[1][1]-z[0][1]
  if (x,y) not in a:
    a[(x,y)] = 1
  else:
    a[(x,y)] += 1
if n == 1:
  print (1)
else:
  print (n-max(a.values()))

Solution (Python):
import itertools
n = int(input())
xy = []

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


a,b = [],[]
for v in itertools.combinations(xy,2):
  z = list(v)
  z.sort()
  x = z[1][0]-z[0][0]
  y = z[1][1]-z[0][1]
  a.append([x,y])
  if [x,y] in b:
    continue
  b.append([x,y])

c = 0
for i in b:
  c = max(c,a.count(i))
print (n-c)

Solution (Python):
n = int(input())
 
difs = {}
points = []
 
for i in range(n):
    x, y = list(map(int, input().split()))
 
    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])
 
        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1
 
    points.append((x, y))
 
if n == 1:
    print(1)
else:
    print(n-max(difs.values()))

Solution (Python):
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])
l=sorted(l)
s=set()
for j in range(n-1):
    for k in range(j,n):
        s.add((l[k][0]-l[j][0],l[k][1]-l[j][1]))
s_l=sorted(list(s))
cnt=[0]*len(s_l)
dic={}
for i in range(len(s_l)):
    dic[s_l[i]]=i
for j in range(n-1):
    for k in range(j+1,n):
        cnt[dic[(l[k][0]-l[j][0],l[k][1]-l[j][1])]]+=1
if n==1:
    print(1)
    exit()
print(n-max(cnt))

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

d = dict()
for point in xy:
    d[str(point)] = 1


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

ans = N
que = deque()

for i in range(N):
    for j in range(i+1, N):
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]

        ans_tmp = N

        for point in xy:
            add = [point[0] + p, point[1] + q]
            
            if d.get(str(add)) == 1:
                ans_tmp -= 1
                d[str(add)] -= 1
                que.append(str(add))
            
            
            
        
        ans = min(ans, ans_tmp)
        
        while len(que):
            key = que.pop()
            d[key] += 1
        


print(ans)

Solution (Python):
import sys
from collections import deque
input = sys.stdin.readline

def main():
  n = int(input())
  ball = [tuple(map(int, input().split())) for i in range(n)]

  ans = n
  for i in range(n):
    for j in range(n):
      p, q = ball[i][0] - ball[j][0], ball[i][1] - ball[j][1]
      par = [-1]*n
      node = [[] for i in range(n)]
      for s in range(n):
        for t in range(n):
          x, y = ball[s][0] - ball[t][0], ball[s][1] - ball[t][1]
          if x == p and y == q:
            node[s].append(t)
            node[t].append(s)
      already = [False]*n
      count = 0
      for k in range(n):
        if already[k]:
          continue
        count += 1
        already[k] = True
        not_yet = deque([k])
        while not_yet:
          key = not_yet.pop()
          for v in node[key]:
            if already[v]:
              continue
            already[v] = True
            not_yet.append(v)
      if ans > count:
        ans = count
  print(ans)

  
main()

Solution (Python):
n = int(input())
A = []
for _ in range(n):
  x, y = map(int, input().split())
  A.append((x, y))
maxc = 0
for i in range(n):
  for j in range(n):
    c = 0
    if i == j:
      continue
    dx = A[i][0] - A[j][0]
    dy = A[i][1] - A[j][1]
    for k in range(n):
      for l in range(n):
        if k == l:
          continue
        if A[k][0] + dx == A[l][0] and A[k][1] + dy == A[l][1]:
          c += 1
    if maxc < c:
      maxc = c
print(n-maxc)

Solution (Python):
n = int(input())
A = []
for _ in range(n):
  x, y = map(int, input().split())
  A.append((x, y))
maxc = 0
for i in range(n):
  for j in range(n):
    c = 0
    if i == j:
      continue
    dx = A[i][0] - A[j][0]
    dy = A[i][1] - A[j][1]
    for k in range(n):
      for l in range(n):
        if k == l:
          continue
        if A[k][0] + dx == A[l][0] and A[k][1] + dy == A[l][1]:
          c += 1
    if maxc < c:
      maxc = c
print(n-maxc)

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

difs = {}
points = []

for i in range(n):
    x, y = list(map(int, input().split()))

    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])

        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1

    points.append((x, y))

if n == 1:
    print(1)
else:
    print(n-max(difs.values()))

Solution (Python):
import sys

import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


n=int(input())
l=[i for i in range(n)]
xy=[list(map(int,input().split()))  for _ in range(n)]
if n==1:
  print(1)
  exit()
comb=itertools.permutations(l,2)
dic={}
for c in comb:
    i,j=c
    xi,yi=xy[i]
    xj,yj=xy[j]
    p=xi-xj
    q=yi-yj
    if (p,q) not in dic:
        dic[(p,q)]=1
    else:
        dic[(p,q)]+=1
res=-1
ai=-1
for i in dic.keys():
    if res<dic[i]:
        ai=i
        res=dic[i]
print(n-dic[ai])

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

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

dis = {}

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        X = XY[j][0]-XY[i][0]
        Y = XY[j][1]-XY[i][1]
        if (X,Y) in dis:
            dis[(X,Y)] += 1
        else:
            dis[(X,Y)] = 1
print(N-max(dis.values()))

Solution (Python):
N=int(input())
if N==1:
  print(1)
  exit()
L=list()
R=list()
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
k=dict()
for i in range(N-1):
  for j in range(i+1,N):
    a,b=L[i]
    c,d=L[j]
    R.append([a-c,b-d])
    n=str(a-c)+" "+str(b-d)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
    R.append([c-a,d-b])
    n=str(c-a)+" "+str(d-b)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
op=max(k.values())
print(N-op)

Solution (Python):
from collections import defaultdict
from typing import Counter

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

ans = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        a = XY[i][0]-XY[j][0]
        b = XY[i][1]-XY[j][1]
        cnt[a][b] += 1
        ans = max(cnt[a][b], ans)

print(N-ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
xy=[]
for _ in range(N):
    xy.append(lint())
xy.sort()
if N==1:
    print(1)
    exit()
C=counter()
for i in range(N):
    for j in range(i+1,N):
        C.add((xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]))
print(N-max(list(C.values())))

Solution (Python):
N = int(input())
l=[]
if N==1:
   print(1)
   exit()
for i in range(N):
   a,b=map(int,input().split())
   l.append((a,b))
l2=[]
for i in range(N):
   for j in range(N):
      if i!=j:
         l2.append((l[i][0]-l[j][0],l[i][1]-l[j][1]))
from collections import Counter
l2=max(Counter(l2).values())
print(N-l2)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

from collections import deque, defaultdict





def solve():
    N = II()
    X = [0] * N
    Y = [0] * N
    for i in range(N):
        x, y = MI()
        X[i], Y[i] = x, y

    dct = defaultdict(int)
    for i in range(N):
        for j in range(N):
            if i == j: continue
            xi, yi = X[i], Y[i]
            xj, yj = X[j], Y[j]

            dct[(xi-xj, yi-yj)] += 1
    
    mx = 0
    for d in dct.values():
        mx = max(mx, d)
    print(N - mx)


if __name__ == '__main__':
    solve()

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

P = []

for i in range(N):
    x,y = map(int,input().split())
    P.append((x,y))

mp = {}

for i in range(N):
    for j in range(i+1,N):
        mp[(P[i][0]-P[j][0],P[i][1]-P[j][1])] = 0
        mp[(P[j][0]-P[i][0],P[j][1]-P[i][1])] = 0

for i in range(N):
    for j in range(i+1,N):
        mp[(P[i][0]-P[j][0],P[i][1]-P[j][1])] += 1
        mp[(P[j][0]-P[i][0],P[j][1]-P[i][1])] += 1

ans = N
for i in mp:
    ans = min(ans,N-mp[i])

print(ans)

Solution (Python):
n= int(input())
if n == 1:
  print(1)
  exit()
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0 or p==0 and q<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))

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

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

from collections import defaultdict

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

cnt = defaultdict(int)
for pi in range(N):
    for pj in range(N):
        if pi == pj:
            continue
        
        dx = P[pi][0] - P[pj][0]

        
        dy = P[pi][1] - P[pj][1]

        cnt[(dx, dy)] += 1

ans = N-max(cnt.values())
print(ans)

Solution (Python):
n=int(input())
p=[]
for i in range(n):
  p.append(list(map(int,input().split())))
p.sort()

c=[set() for i in range(n)]
for i in range(n):
  for j in range(n):
    c[i].add((p[i][0]-p[j][0],p[i][1]-p[j][1]))
mn=1 if n==1 else 100
for i in range(n):
  for j in range(i+1,n):
    cnt=0
    pq=(p[i][0]-p[j][0],p[i][1]-p[j][1])
    for k in range(n):
      if not(pq in c[k]):
        cnt+=1
    mn=min(mn,cnt)
print(mn)

Solution (Python):






N = int(input())
X = []; Y = []
for _ in range(N):
    x,y = map(int, input().split())
    X += [x]
    Y += [y]





dic = {}
for i in range(N):
    for j in range(N):
        if i != j:
            x = X[i]-X[j]
            y = Y[i]-Y[j]
            dic[(x,y)] = dic.get((x,y),0) + 1
if N == 1:
    print(1)
else:
    print(N-max(dic.values()))

Solution (Python):
N = int(input())
S = list(tuple(map(int, input().split())) for _ in range(N))
A = []
if N == 1:
    print(1)
else:
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            a, b = S[i]
            c, d = S[j]
            for k in range(len(A)):
                e, f, g = A[k]
                if e == a-c and f == b-d:
                    A[k] = (e, f, g+1)
                    break
            else:
                A.append((a-c, b-d, 1))
    print(N-max(list(x[2] for x in A)))

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

count=[]
for x1,y1 in xy:
    for x2,y2 in xy:
        if x1==x2 and y1==y2:
            continue
        c=str(x1-x2)+':'+str(y1-y2)
        count.append(c)

from collections import*
C=Counter(count)
C['zentsu999']=0
print(N-max(C.values()))

Solution (Python):
import sys
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    balls = [tuple(map(int, input().split())) for _ in range(N)]
    comb = list(itertools.combinations(balls, 2))
    ans = 0
    for c in comb:
        a, b = c
        p = b[0] - a[0]
        q = b[1] - a[1]
        ans_i = 0
        for d in balls:
            e = (d[0] + p, d[1] + q)
            if e in balls:
                ans_i += 1
        ans = max(ans, ans_i)
    print(N - ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
pts=[list(map(int,input().split())) for _ in range(n)]

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

ans=100

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    for j in range(i+1,n):
        x1,y1=pts[i]
        x2,y2=pts[j]

        p=x1-x2
        q=y1-y2

        visit=[0]*n
        
        cur=0
        for k in range(n):
            if visit[k]==1:
                continue
            cur+=1
            x3,y3=pts[k]
            cx=x3
            cy=y3
            while my_index(pts,[cx,cy])>=0:
                visit[my_index(pts,[cx,cy])]=1
                cx+=p
                cy+=q
            cx=x3
            cy=y3
            while my_index(pts,[cx,cy])>=0:
                visit[my_index(pts,[cx,cy])]=1
                cx-=p
                cy-=q
        
        ans=min(ans,cur)
    
print(ans)

Solution (Python):
N = int(input())
l=[]
if N==1:
   print(1)
   exit()
for i in range(N):
   a,b=map(int,input().split())
   l.append((a,b))
l2=[]
for i in range(N):
   for j in range(N):
      if i!=j:
         l2.append((l[i][0]-l[j][0],l[i][1]-l[j][1]))
from collections import Counter
l2=max(Counter(l2).values())
print(N-l2)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    N = int(input().strip())
    XY = []
    for i in range(N):
        x, y = map(int, input().strip().split())
        XY.append((x, y))
    return N, XY


def solve(N, XY):
    if N == 1:
        return 1

    min_cost = 1000000
    for j in range(N):
        for i in range(j):
            rdict = defaultdict(list)
            x0, y0 = XY[i]
            x1, y1 = XY[j]
            p, q = x1 - x0, y1 - y0
            for k in range(N):
                x, y = XY[k]
                rdict[q * x - p * y].append((x, y))
            cost = 0
            for v in rdict.values():
                vs = list(sorted(v))
                x0, y0 = vs[0]
                for x1, y1 in vs:
                    if x1 - x0 != p or y1 - y0 != q:
                        cost += 1
                    x0, y0 = x1, y1
            min_cost = min(min_cost, cost)
    return min_cost


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Solution (Python):
from collections import *

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

if N==1:
    print(1)
    exit()
    
cnt = defaultdict(int)

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        
        cnt[(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])] += 1

M = max(list(cnt.values()))
print(N-M)

Solution (Python):
N = int(input())
graph = []
for _ in range(N):
    x, y = map(int, input().split())
    graph.append([x, y])
if N == 1:
    print(1)
    exit()
ans = float('inf')
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = graph[i][0] - graph[j][0]
        q = graph[i][1] - graph[j][1]
        vec_cnt = 0
        for k in range(N):
            for l in range(N):
                if p == graph[k][0] - graph[l][0] and q == graph[k][1] - graph[l][1]:
                    vec_cnt += 1
        ans = min(ans, N - vec_cnt)
print(ans)

Solution (Python):
from collections import *
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
a=[]
for i in range(n):
  for j in range(n):
    if i==j:continue
    a+=[(x[i]-x[j],y[i]-y[j])]
c=list(Counter(a).values())
print(n-max(c) if c else n)

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

delta = []
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        delta.append((dx, dy))

c_delta = collections.Counter(delta)

if len(c_delta):
    print(n-c_delta.most_common()[0][1])
else:
    print(1)

Solution (Python):
from collections import defaultdict
n = int(input())
balls = []
diffs = [[None] * n for _ in range(n)]
for _ in range(n):
    x, y = [int(i) - 1 for i in input().split()]
    balls.append((x, y))

d = defaultdict(int)


for i in range(n):
    for j in range(n):
        ax, ay = balls[i]
        bx, by = balls[j]
        diffs[i][j] = (bx - ax, by - ay)
        if bx - ax != 0 or by - ay != 0:  
            d[(bx - ax, by - ay)] += 1

_max = 0

for k, v in d.items():
    _max = max(_max, v)

print(n - _max)

Solution (Python):
from decimal import Decimal

N = int(input())

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

cnt ={}

for i in range(N):
    xi = xy[i][0]
    yi = xy[i][1]

    for j in range(i+1,N):
        xj = xy[j][0]
        yj = xy[j][1]

        x_dif =xi-xj
        y_dif = yi-yj
        if x_dif<0:
            x_dif = -x_dif
            y_dif = -y_dif
        elif x_dif == 0:
            y_dif = abs(y_dif)

        if (x_dif,y_dif)  in cnt.keys():
            cnt[x_dif,y_dif] += 1
        else:
            cnt[x_dif, y_dif] =1

if N == 1:
    print(1)
else: print(N-max(cnt.values()))

Solution (Python):
class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        n:要素数
        """
        self.n=N
        self.parents=[-1]*N
        self.rank=[0]*N

    def find(self, x):
        """要素xの属している族を調べる.

        x:要素
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """要素x,yを同一視する.

        x,y:要素
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x]>self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y

            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1

    def size(self, x):
        """要素xの属している要素の数.

        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.
        ※族の要素の個数が欲しいときはsizeを使うこと!!

        x:要素
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """族の名前のリスト
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """族の個数
        """
        return len(self.roots())

    def all_group_members(self):
        """全ての族の出力
        """
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N=int(input())
P=[0]*N

for i in range(N):
    x,y=map(int,input().split())
    P[i]=(x,y)

M=float("inf")
for i in range(N):
    for j in range(N):
        p=P[j][0]-P[i][0]
        q=P[j][1]-P[i][1]

        U=Union_Find(N)
        for k in range(N):
            for l in range(N):
                if P[l]==(P[k][0]+p,P[k][1]+q):
                    U.union(k,l)

        M=min(M,U.group_count())
print(M)

Solution (Python):
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    c = collections.Counter()

    if N == 1:
        print(1)
        return

    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            xi, yi = XY[i]
            xj, yj = XY[j]
            c[(xi - xj, yi - yj)] += 1

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


if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
if n==1:
    print(1)
    exit()
xy = []
for i in range(n):
    xy.append(tma())
co = collections.Counter()

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        x1,y1 = xy[i]
        x2,y2 = xy[j]
        co[(x2-x1,y2-y1)] +=1

ans = 10**9
for num in co.values():
    ans = min(ans,n-num)
print(ans)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
if n==1:
    print(1)
    exit()
xy = []
for i in range(n):
    xy.append(tma())
co = collections.Counter()

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        x1,y1 = xy[i]
        x2,y2 = xy[j]
        co[(x2-x1,y2-y1)] +=1

ans = 10**9
for num in co.values():
    ans = min(ans,n-num)
print(ans)

Solution (Python):
from collections import *
(n,),*p=[[*map(int,i.split())] for i in open(0)]
d=defaultdict(int)
for x, y in p:
    for a, b in p:
        d[(x-a, y-b)]+=(x,y)!=(a,b)
print(n-max(d.values()))

Solution (Python):

from collections import defaultdict

(n, ), *p = [[*map(int, i.split())] for i in open(0)]
d = defaultdict(int)
for i in range(n):
    for j in range(n):
            d[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += i!=j
print(n - max(d.values()))

Solution (Python):

from collections import defaultdict

(n, ), *p = [[*map(int, i.split())] for i in open(0)]
d = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i != j:
            d[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += 1
print(n*(n<2) or n - max(d.values()))

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

A = sorted(A)

d = defaultdict(int)
for i in range(N):
    x1, y1 = A[i]
    for j in range(i + 1, N):
        x2, y2 = A[j]
        d[(x2 - x1, y2 - y1)] += 1

freq = 0
for v in d.values():
    freq = max(freq, v)
print(N - freq)

Solution (Python):
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()

Solution (Python):
from itertools import combinations


def main():
    N = int(input())
    points = [list(map(int, input().split())) for _ in range(N)]
    ans = N
    for i, j in combinations(range(N), 2):
        p1, p2 = points[i], points[j]
        if p1 == p2:
            continue
        dx, dy = p1[0] - p2[0], p1[1] - p2[1]
        cost = N
        for k, l in combinations(range(N), 2):
            p3, p4 = points[k], points[l]
            if (p3[0] + dx == p4[0] and p3[1] + dy == p4[1]) or \
                    (p4[0] + dx == p3[0] and p4[1] + dy == p3[1]):
                cost -= 1
        ans = min(ans, cost)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
(n,),*xy = [list(map(int, s.split())) for s in open(0)]

from collections import Counter
from itertools import combinations
from sys import exit

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

c = Counter()

for (xa,ya),(xb,yb) in combinations(xy,2):
    c[(xa-xb, ya-yb)] += 1
    c[(xb-xa, yb-ya)] += 1

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

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

pq = []
for i in range(N):
    for j in range(N):
        if i != j:
            x1 = xy[i][0]
            y1 = xy[i][1]
            x2 = xy[j][0]
            y2 = xy[j][1]
            pq.append((x2 - x1, y2 - y1))

ans = N
for p,q in pq:
    tmp = 0
    for i in range(N):
        for j in range(N):
            if i != j:
                x1 = xy[i][0]
                y1 = xy[i][1]
                x2 = xy[j][0]
                y2 = xy[j][1]
                if x2 - x1 == p and y2 - y1 == q:
                    tmp += 1
    ans = min(ans, N - tmp)

print(ans)

Solution (Python):

from collections import defaultdict

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

X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
    for j in range(i + 1, N):
        p = X[i][0] - X[j][0]
        q = X[i][1] - X[j][1]
        ctr[(p, q)] += 1
        ctr[(-p, -q)] += 1

if N == 1:
    print(1)
else:
    print(N - max(ctr.values()))

Solution (Python):
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    if N==1:
        print(1)
        sys.exit()
    XY = list(list(map(int, readline().split())) for _ in range(N))
    d = defaultdict(int)
    for i in range(N-1):
        x1, y1 = XY[i]
        for j in range(i+1,N):
            x2, y2 = XY[j]
            x = x2-x1
            y = y2-y1
            d[x,y] += 1
            d[-x,-y] += 1
    print(N-max(d.values()))



if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
X = [0]*n
Y = [0]*n
for i in range(n):
  X[i],Y[i] = map(int,input().split())  
  
dic = {}
for i in range(n):
  for j in range(n):
    if i!=j:
      x = X[i]-X[j]
      y = Y[i]-Y[j]
      dic[(x,y)] = dic.get((x,y),0) + 1

if n == 1:
  print(1)
else:  
  print(n-max(dic.values()))