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,math,collections,itertools
input = sys.stdin.readline

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

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

for _ in range(N):
    xy.append(list(map(int,input().split())))

rxy = []
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        rxy.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))
cr = collections.Counter(rxy)
print(N-max(cr.values()))

Solution (Python):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    x, y = [0]*n, [0]*n
    for i in range(n):
        x[i], y[i] = map(int, input().split())
    from collections import defaultdict
    xy = defaultdict(int)
    for i in range(n):
        for j in range(n):
            if i == j: continue
            xy[(x[i]-x[j], y[i]-y[j])] += 1
    if xy == {}:
        print(1)
        return
    p, q = max(xy, key=lambda x: xy[x])
    ans = n
    for i in range(n):
        for j in range(n):
            if i == j: continue
            if x[i]-x[j] == p and y[i]-y[j] == q:
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, 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 = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, 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())


def main():
    from itertools import combinations
    n = int(readline())
    mat = [list(map(int, readline().split())) for _ in range(n)]

    if n == 1:
        return print(1)

    ans = INF
    for com in combinations(range(n), r=2):
        first, second = com
        dx = mat[first][0] - mat[second][0]
        dy = mat[first][1] - mat[second][1]
        uf = UnionFind(n)
        for i in range(n):
            cx, cy = mat[i]
            for j in range(n):
                nx, ny = mat[j]
                if (cx - nx == dx and cy - ny == dy) or (-cx + nx == dx and - cy + ny == dy):
                    uf.union(i, j)
        ans = min(ans, uf.group_count())

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
(n,), *z = [[*map(int, o.split())] for o in open(0)]
if n == 1:
    print(1)
    exit()
from itertools import*
from collections import*
print(n - Counter((z[i][0] - z[j][0], z[i][1] - z[j][1]) for i, j in permutations(range(n), 2)).most_common()[0][1])

Solution (Python):
(n,),*a=[[*map(int,i.split())]for i in open(0)]
d={0:0}
for i,j in a:
    for x,y in a:
        if i!=x or j!=y:
            d[(i-x,j-y)]=d.get((i-x,j-y),0)+1
print(n-max(d.values()))

Solution (Python):
(n,),*a=[[*map(int,i.split())]for i in open(0)]
d={}
for i,j in a:
    for x,y in a:
        if i!=x or j!=y:
            d[(i-x,j-y)]=d.get((i-x,j-y),0)+1
print(n-max(list(d.values())+[0]))

Solution (Python):
from itertools import permutations
n = int(input())
point_ls = [0] * n
for i in range(n):
    point_ls[i] = list(map(int, input().split()))
ind_ls = [i for i in range(n)]
diff_ls = []
for start, end in permutations(ind_ls, 2):
    diff = [0] * 2
    diff[0] = point_ls[end][0] - point_ls[start][0]
    diff[1] = point_ls[end][1] - point_ls[start][1]
    diff_ls.append(diff)
ans = 0
for diff in diff_ls:
    same = 0
    for diff2 in diff_ls:
        if diff == diff2:
            same += 1
    ans = max(ans, same)
print(n-ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    xy = [LI() for _ in range(N)]

    if N == 1:
        print(1)
    else:
        interval = []
        for i in range(N):
            for j in range(N):
                if i != j:
                    interval.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))

        cnt = collections.Counter(interval)
        nocost = max(cnt.values())
        ans = N - nocost
        print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import Counter
N = int(input())
X = []
for _ in range(N):
  X.append(list(map(int, input().split())))
  
if N == 1:
  print(1)
  exit(0)
A = []
for i in range(N):
  for j in range(N):
    if i==j:
      continue
    A.append((X[i][0]-X[j][0], X[i][1]-X[j][1]))
    
C = Counter(A)
print(N - C.most_common()[0][1])

Solution (Python):
N = int(input())
INF = int(1e13)
A = [list(map(int, input().split())) for _ in range(N)]
X = [[[0, 0] for __ in range(N)] for _ in range(N)]
for i in range(N):
  for j in range(N):
    X[i][j] = [A[i][0]-A[j][0], A[i][1] - A[j][1]]
for i in range(N):
  X[i][i][0], X[i][i][1] = INF + 2*i, INF + 2*i+1
D = {}
for i in range(N):
  for j in range(N):
    if X[i][j][0]*(10*INF)+X[i][j][1] in D:
      D[X[i][j][0]*(10*INF)+X[i][j][1]] += 1
    else:
      D[X[i][j][0]*(10*INF)+X[i][j][1]] = 1
if N == 1:
  print(1)
else:
  print(N-max(D[i] for i in D))

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, 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 = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    
    def count_group(self):
        return len({self.find(x) for x in range(N)})

N = getN()
que = [getList() for i in range(N)]
if N == 1:
    print(1)
    exit()

dis = []

for i in range(N):
    for j in range(i + 1, N):
        dis.append([que[i][0] - que[j][0], que[i][1] - que[j][1]])

ans = float('inf')
for p, q in dis:
    U = UnionFind(N)
    for i in range(N):
        for j in range(i + 1, N):
            if (que[i][0] + p == que[j][0] and que[i][1] + q == que[j][1]) or (que[i][0] - p == que[j][0] and que[i][1] - q == que[j][1]):
                U.union(i, j)
    ans = min(ans, U.count_group())
print(ans)

Solution (Python):
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)]
 
a = []
for i in range(n):
    for j in range(n):
        if i != j:
            a.append((x[j][0]-x[i][0], x[j][1]-x[i][1]))
 
a.sort()
count = 1
reg = 1

for i in range(1, len(a)):
    if a[i][:] == a[i-1][:]:
        count += 1
        reg = max(reg, count)
    else:
        count = 1

if n == 1:
    ans = n
else:
    ans = n - reg

print(ans)

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

Solution (Python):
from collections import defaultdict
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]

cnt = defaultdict(int)
cnt[(0, 0)] = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        cnt[(points[i][0] - points[j][0], points[i][1] - points[j][1])] += 1


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

Solution (Python):
import sys
from collections import defaultdict
from itertools import combinations

input = sys.stdin.readline


def main():
    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)
        sys.exit()

    vector = defaultdict(int)
    for a, b in combinations(range(N), 2):
        dx = x[a] - x[b]
        dy = y[a] - y[b]
        if dx == 0:
            vector[(0, abs(dy))] += 1
        elif dx > 0:
            vector[(dx, dy)] += 1
        else:
            vector[(-dx, -dy)] += 1

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


if __name__ == "__main__":
    main()

Solution (Python):



n = int(input())
if n == 1:
    print(1)  
    exit()
points = []
for _ in range(n):
    points.append(list(map(int, input().split())))

ans = 10**18
for p in range(n):
    for q in range(n):
        if p == q:
            continue
        vector = [points[p][0] - points[q][0], points[p][1] - points[q][1]]
        tmp = 0
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                if points[i][0] - points[j][0] == vector[
                        0] and points[i][1] - points[j][1] == vector[1]:
                    tmp += 1

        ans = min(ans, n - tmp)

print(ans)

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

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

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

distance = {}

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if (ball_xy[i][0]-ball_xy[j][0], ball_xy[i][1]-ball_xy[j][1]) in distance:
            distance[(ball_xy[i][0]-ball_xy[j][0], ball_xy[i][1]-ball_xy[j][1])] += 1
        else:
            distance[(ball_xy[i][0]-ball_xy[j][0], ball_xy[i][1]-ball_xy[j][1])] = 1

cost_0 = max(distance.values())

print(n-cost_0)

Solution (Python):
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(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
        v = x[j] - x[i], y[j] - y[i]
        if v not in a:
            a[v] = 1
        else:
            a[v] += 1
ans = n

if len(a.values()) > 0:
    ans -= max(a.values())
print(ans)

Solution (Python):
n=int(input())
if n==1:
    print(1)
    exit()
x=[]
for i in range(n):
    a,b=map(int,input().split())
    x.append([a,b])
x.sort()
ans=float("inf")
for i in range(n-1):
    for j in range(i+1,n):
        p,q=x[j][0]-x[i][0],x[j][1]-x[i][1]
        cnt=0
        flg=[False for i in range(n)]
        for k in range(n):
            if flg[k]==False:
                flg[k]=True
                cnt+=1
                fl=True
                xx,yy=x[k][0],x[k][1]
                while fl:
                    nx,ny=xx+p,yy+q
                    if [nx,ny] in x:
                        a=x.index([nx,ny])
                        flg[a]=True
                        xx,yy=nx,ny
                    else:
                        fl=False
        if cnt<ans:
            ans=cnt
print(ans)

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

res = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[i] - x[j]
        q = y[i] - y[j]
        
        cnt = 0
        for ii in range(N):
            for jj in range(N):
                pp = x[jj] - p
                qq = y[jj] - q
                if ii == jj:
                    continue
                if pp == x[ii] and qq == y[ii]:
                    cnt += 1
            res = max(res, cnt)

print(N - res)

Solution (Python):
from collections import Counter
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
dXY = Counter([])
for i in range(n):
    for j in range(n):
        if i!=j:
            dXY += Counter([str(XY[i][0]-XY[j][0])+'_'+str(XY[i][1]-XY[j][1])])
if n==1:
    print(1)
else:
    print(n-dXY.most_common()[0][1])

Solution (Python):
from collections import defaultdict
n = int(input())
li = []
for i in range(n):
    x, y = map(int, input().split())
    li.append((x, y))
dd = defaultdict(lambda:0)
for i in range(n):
    for j in range(n):
        if i != j:
            dd[(li[i][0]-li[j][0], li[i][1]-li[j][1])] += 1
m = 0
for k in dd:
    m = max(dd[k],m)
print(n-m)

Solution (Python):
from collections import defaultdict

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

cnt = defaultdict(int)
for xi, yi in xy:
    for xj, yj in xy:
        cnt[(xi - xj, yi - yj)] += 1
cnt[(0, 0)] = 0
ans = n - max(cnt.values())
print(ans)

Solution (Python):
import itertools
def main():
  N = int(input())
  posi = []
  for i in range(N):
    posi.append(list(map(int, input().split())))
  posi.sort()
  num = [i for i in range(N)]
  ans = 1000000000
  for pair in itertools.combinations(num,2):
    p = posi[pair[1]][0]-posi[pair[0]][0]
    q = posi[pair[1]][1]-posi[pair[0]][1]
    ch = [True]*N
    ans_temp = 0
    for i in range(N):
      if ch[i]:
        ans_temp += 1
        ch[i] = False
      now = posi[i]
      while [now[0] +  p, now[1] + q] in posi:
        ch[posi.index([now[0] +  p, now[1] + q])] = False
        now = [now[0] +  p, now[1] + q]
    ans = min(ans, ans_temp)
  if N == 1:
    ans = 1
  print(ans)
    
  
if __name__ == "__main__":
  main()

Solution (Python):
from itertools import permutations
from collections import Counter

N,*xyf = map(int, open(0).read().split())
xy = [(xyf[i*2],xyf[i*2+1]) for i in range(N)]
if N == 1:
    print(1)
else:
    count = []
    for a, b in permutations(xy,2):
        count.append((b[0]-a[0],b[1]-a[1]))
    c = Counter(count)
    print(N-max(c.values()))

Solution (Python):
N = int(input())
lis = []
for i in range(N):
    lis.append(tuple(map(int, input().split())))
if N == 1:
    print(1)
    exit()

dic = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        val = (lis[i][0]-lis[j][0], lis[i][1]-lis[j][1])
        if val in dic:
            dic[val] += 1
        else:
            dic[val] = 1

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

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

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


if n == 1:
    print(1)
else:
    diff = {}
    
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            vec = (balls[i][0]-balls[j][0], balls[i][1]-balls[j][1])
            if vec not in diff:
                diff[vec] = 1
            else:
                diff[vec] += 1
    
    print(n-max(diff.values()))

Solution (Python):
import sys
import itertools
from collections import defaultdict

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    xy = [tuple(in_nn()) for _ in range(N)]

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

    comb = itertools.combinations(range(N), 2)
    d = defaultdict(int)

    for i, j in comb:
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        xd = x2 - x1
        yd = y2 - y1
        d[(xd, yd)] += 1
        d[(-xd, -yd)] += 1

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

mod = 998244353
from decimal import *



N = INT()
xy = [LIST() for _ in range(N)]
xy.sort(key = lambda x:(x[0], x[1]))

delta = defaultdict(int)
if N == 1:
	print(1)
else:
	for x, y in combinations(xy, 2):
		delta[(y[0]-x[0], y[1]-x[1])] += 1

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

mod = 998244353
from decimal import *



N = INT()
xy = [LIST() for _ in range(N)]
xy.sort(key = lambda x:(x[0], x[1]))

delta = defaultdict(int)
if N == 1:
	print(1)
else:
	for x, y in combinations(xy, 2):
		delta[(y[0]-x[0], y[1]-x[1])] += 1

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

def sub(p,q):
    seen = [False]*n
    ans = 0
    for start in range(n):
        if seen[start]:
            continue
        ans += 1
        qq = [start]
        seen[start] = True
        while qq:
            u = qq.pop()
            for i,(x,y) in enumerate(xys):
                if seen[i]:
                    continue

                if (xys[u][0]-x, xys[u][1]-y) == (p,q) or (xys[u][0]-x, xys[u][1]-y) == (-p,-q):
                    qq.append(i)
                    seen[i] = True
    return ans
ans = 10**10
for i in range(n):
    for j in range(n):
        p = xys[i][0]-xys[j][0]
        q = xys[i][1]-xys[j][1]
        val = sub(p,q)
        ans = min(ans, val)
print(ans)

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

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

cnt=0
for p,q in pq:
  t_cnt=0
  for x,y in xy:
    if [x+p,y+q] in xy:
      t_cnt+=1
  cnt=max(cnt,t_cnt)

print(n-cnt)

Solution (Python):
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n - 1):
    xi, yi = xy[i]
    for j in range(i + 1, n):
        xj, yj = xy[j]
        cost = 0
        for x, y in xy:
            cost += 1 if [x - xj + xi, y - yj + yi] in xy else 0
    cnt = max(cnt, cost)
print(n - cnt)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

mod = 998244353
from decimal import *



N = INT()
xy = [LIST() for _ in range(N)]

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

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

for s, t in combinations(xy, 2):
	st = str(t[0]-s[0]) + " " +str(t[1]-s[1])
	diff.append(st)

print(max(N - Counter(diff).most_common()[0][1], 1))

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

    d = [[(0,0)] * N for _ in range(N)]
    b = set()
    for i in range(N):
        for j in range(N):
            d[i][j] = (X[i][0] - X[j][0], X[i][1] - X[j][1])
            if not (X[i][0] - X[j][0] == 0 and X[i][1] - X[j][1] == 0):
                b.add((X[i][0] - X[j][0], X[i][1] - X[j][1]))
    
    cnt = 0
    for a in b:
        tmp = 0
        for i in range(N):
            tmp += d[i].count(a)

        cnt = max(cnt, tmp)
    
    print(1 + (N - 1 - cnt))
            


if __name__ == "__main__":
    main()

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union































def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    

    def calc_cost(p, q, points):
        selected = [False] * n
        cnt = 0
        for i in range(n):
            if not selected[i]:
                selected[i] = True
                cnt += 1
                x, y = points[i]
                while True:
                    if [x + p, y + q] in points:
                        selected[points.index([x + p, y + q])] = True
                        x, y = x + p, y + q
                    else:
                        break
                x, y = points[i]
                while True:
                    if [x - p, y - q] in points:
                        selected[points.index([x - p, y - q])] = True
                        x, y = x - p, y - q
                    else:
                        break
        return cnt
    
    
    n = ii()
    points = [lmi() for _ in range(n)]

    if n == 1:
        print(1)
    else:
        cost = inf
        for i in range(n):
            for j in range(n):
                if i != j:
                    p = points[i][0] - points[j][0]
                    q = points[i][1] - points[j][1]
                    cost = min(cost, calc_cost(p, q, points))
        print(cost)



if __name__ == "__main__":
    main()

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    
    class UnionFind():
        """
        parents : 親要素(findしない場合は根ではないことの注意)，根の場合は"-(要素数）"
        find(x):要素xの属するグループの根を返す
        size(x):要素xの属するグループの要素数を返す
        same(x,y):x,yが同じグループに属しているか返す
        members(x):要素xが属するグループに属する要素をリストで返す
        roots:全ての根の要素を返す
        group_count():グループの数を返す
        all_group_members():{根要素：[そのグループに含まれる要素のリスト]}の辞書を返す
        """
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, 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 = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

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

        def members(self, 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())
    



    mod=10**9+7
    N=I()
    X=[0]*N
    Y=[0]*N
    for i in range(N):
        X[i],Y[i]=MI()
    
    ans=N
    
    for ii in range(N):
        for jj in range(N):
            p=X[ii]-X[jj]
            q=Y[ii]-Y[jj]
            uf=UnionFind(N)
    
            for j in range(N):
                for k in range(N):
                    if X[k]-X[j]==p and Y[k]-Y[j]==q:
                        uf.union(j,k)
            temp=uf.group_count()
            ans=min(ans,temp)
    print(ans)
        
        

main()

Solution (Python):

def main():
    N = int(input())
    if N == 1:print(1);exit();
    x = [None] * N
    y = [None] * N
    for i in range(N):
        x[i], y[i] = map(int, input().split())
    
    diff = []
    nums = []
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            if (x[j]-x[i],y[j]-y[i]) in diff:
                nums[diff.index((x[j]-x[i],y[j]-y[i]))] += 1
            else:
                diff.append((x[j]-x[i],y[j]-y[i]))
                nums.append(1)
    
    
    print(N-max(nums))

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = [inpl() for _ in range(n)]
if n == 1:
    print(1)
    quit()
c = []
for i,(x,y) in enumerate(a):
    for j,(z,w) in enumerate(a):
        if i == j: continue
        c.append(((x-z), (y-w)))
h = Counter(c)
print(n-max(h.values()))