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):
from collections import Counter, defaultdict
import sys
N = int(input())
x = []
for i in range(N):
    a, b = map(int, input().split())
    x.append([a, b])
if N == 1:
    print(1)
    sys.exit()
x.sort()
cost = []
for i, y in enumerate(x):
    for j, z in enumerate(x):
        if i == j:
            continue
        else:
            num = 0
            a = z[0]-y[0]
            b = z[1]-y[1]
            for w in x:
                c = w[0]
                d = w[1]
                if [a+c, b+d] in x:
                    num += 1
            cost.append(N-num)
print(min(cost))

Solution (Python):


from itertools import permutations
from collections import Counter

def main():
  n = int(input())
  x = []
  y = []

  if n == 1:
    print(1)
    return

  for i in range(n):
    x_tmp, y_tmp = map(int, input().split(' '))
    x.append(x_tmp)
    y.append(y_tmp)

  cnt = Counter()

  for i, j in permutations(range(n), 2):
    dist = (x[i] - x[j], y[i]- y[j])
    cnt[dist] += 1

  dist, c = cnt.most_common(1)[0]
  print(n - c)

if __name__ == '__main__':
  main()

Solution (Python):
from collections import Counter
import itertools

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort()
if N == 1:
        print(1)
        exit()

ptn=list(itertools.combinations(xy,2))
pq=[]
for idx,val in enumerate(ptn):
        if val[1][0]-val[0][0] <= 0 and val[1][1]-val[0][1] <= 0:
                pq.append(str(abs(val[1][0]-val[0][0])) + 'x' + str(abs(val[1][1]-val[0][1])))
        else:
                pq.append(str(val[1][0]-val[0][0]) + 'x' + str(val[1][1]-val[0][1]))

cpq = Counter(pq)


redsc=cpq.most_common(1)[0][1]


print(N-redsc)

Solution (Python):
from collections import Counter
n=int(input())
x=[]
y=[]
for i in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)
cost=n
list=[]
for i in range(n):
  for j in range(n):
    if i != j:
      list.append([x[i]-x[j],y[i]-y[j]])

if n ==1:
  print(cost)
else:
  c=Counter(map(tuple, list))
  mode=c.most_common(1)
  print(cost-mode[0][1])

Solution (Python):
from itertools import combinations

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

memo = dict()
for (a, b) in combinations(P, 2):
    p, q = a[0] - b[0], a[1] - b[1]
    if p < 0:
        p, q = -p, -q
    elif p == 0 and q < 0:
        q = -q
    if (p, q) in memo:
        memo[(p, q)] += 1
    else:
        memo[(p, q)] = 1

print(N - max(memo.values()) if N > 1 else 1)

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


sabun = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            p = xy[i][0] - xy[j][0]
            q = xy[i][1] - xy[j][1]
            sabun.append([p,q])
count = [sabun.count(i)+sabun.count([-i[0],-i[1]]) for i in sabun]

if count == []:
    print("1")
else:
    print(int(N-(max(count))/2))

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

if n == 1:
  print(1)
else:
  
  xy_s = [[int(v) for v in input().split()] for _ in range(n)]
  v = {}
  for i in range(n):
    for j in range(n):
      if i == j:
        continue
      dx = xy_s[i][0] - xy_s[j][0]
      dy = xy_s[i][1] - xy_s[j][1]
      pq = (dx, dy)
      if pq in v:
        v[pq] += 1
      else:
        v[pq] = 1
    
      
  
  counts = v.values()
  m = max(counts)
  ans = n - m
  
  print(ans)

Solution (Python):
import sys
from collections import deque
from collections import defaultdict
import math
import copy
input = sys.stdin.readline
sys.setrecursionlimit(20000000)
n = int(input())
a = set()
for i in range(n):
        x,y = map(int,input().split())
        a.add((x,y))
b = list(a)
c = copy.deepcopy(b)
c.sort()
ans = 500
for i in range(n):
        for j in range(n):
                a = copy.deepcopy(c)
                x = b[i][0] - b[j][0]
                y = b[i][1] - b[j][1]
                tmp = 0
                while a:
                        f,g = a.pop()
                        while (f-x,g-y) in a:
                                a.remove((f-x,g-y))
                                f = f-x
                                g = g-y
                        tmp += 1
                ans = min(ans,tmp)
print(ans)

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

def main():
	n = int(input())
	xy = []
	for _ in range(n):
		xy +=[list(map(int,input().split()))]
	xy.sort(key=lambda x:(x[0],x[1]))
	dic = {}
	for i in range(n):
		for j in range(i+1,n):
			x,y = xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]
			if x*y == 0:
				temp = "{}.{}".format(x,y)
			else:
				k = "" if x*y > 0 else "-"
				x = abs(x)
				y = abs(y)
				temp = "{}.{}{}".format(x,k,y)
			if temp in dic:
				dic[temp] = dic[temp]+1
			else:
				dic[temp] = 1
	mans = 0
	for i in dic:
		mans = max(mans, dic[i])
	ans = n - mans
	print(ans)
	return

main()

Solution (Python):
N=int(input())
s=[list(map(int,input().split())) for i in range(N)]
ans=N
for i in range(N):
    for j in range(i):
        cnt=N
        p=s[i][0]-s[j][0]
        q=s[i][1]-s[j][1]
        for k in range(N):
            if [s[k][0]+p,s[k][1]+q] in s:
                cnt-=1
        ans=min(ans,cnt)

print(ans)

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

counts = {}
for i in range(N):
	x1, y1 = balls[i]
	for j in range(i):
		x2, y2 = balls[j]
		p = x2 - x1
		q = y2 - y1
		if p < 0 or (p == 0 and q < 0):
			p = -p
			q = -q
		diff = (p, q)
		if diff in counts:
			s, l = counts[diff]
			s.add(i)
			s.add(j)
			l.append((i, j))
		else:
			counts[diff] = ({i, j}, [(i, j)])


min_cost = N
min_pq = None
for pq in counts:
	s, l = counts[pq]
	n = len(s)
	c = len(l)
	cost = (N - n) + n - (c + 1) + 1
	if cost < min_cost:
		min_cost = cost
		min_pq = pq
print(min_cost)

Solution (Python):
from fractions import Fraction
from collections import defaultdict
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

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


def calc(p,q):
    result = defaultdict(set)
    for x,y in XY:
        result[x].add(y)

    count = 0
    for x in result.keys():
        for y in result[x]:
            if x-p in result and y-q in result[x-p]:
                continue
            count +=1

    return count


ans = 5000

for i in range(N-1):
    for j in range(i+1,N):
        p = XY[i][0] - XY[j][0]
        q = XY[i][1] - XY[j][1]
        
        ans = min(ans,calc(p,q))

if ans == 5000:
    raise ValueError
print(ans)

Solution (Python):
from itertools import combinations
import sys

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

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


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

combo = list(combinations(X_Y, 2))
diff = [0] * (len(combo))

dict_diff = {}

for i, item in enumerate(combo):
    x_dif = item[0][0] - item[1][0]
    y_dif = item[0][1] - item[1][1]
    diff[i] = [x_dif, y_dif]
    if str(diff[i]) in dict_diff:
        dict_diff[str(diff[i])] += 1
    else:
        dict_diff[str(diff[i])] = 1
    
    x_dif = item[1][0] - item[0][0]
    y_dif = item[1][1] - item[0][1]
    diff[i] = [x_dif, y_dif]
    if str(diff[i]) in dict_diff:
        dict_diff[str(diff[i])] += 1
    else:
        dict_diff[str(diff[i])] = 1

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

Solution (Python):
from collections import Counter
n=int(input())
balls=[]
distance=[]
if n==1:
  print(1)
else:
  for i in range(n):
    balls.append(list(map(int,input().split())))
    balls.sort(key=lambda x:x[0]+x[1])
  for i in range(n-1):
    for j in range(i+1,n):
      distance.append(str(balls[i][0]-balls[j][0])+","+str(balls[i][1]-balls[j][1]))
  d=Counter(distance)
  print(n-d.most_common()[0][1])

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import collections

n = ni()

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

balls = []
dis = []

for i in range(n):
    x,y = na()
    for b in balls:
        k = '_1' if (b[0]-x)*(b[1]-y) > 0 else '_0'
        dis.append(str(abs(b[0]-x))+'_'+str(abs(b[1]-y))+k)
    balls.append([x,y])

c = collections.Counter(dis)
m = c.most_common()

if len(m) == 1:
    print(1)
    exit()

u = m[0][1]

print(n-u)

Solution (Python):
from collections import Counter


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

vector = [0] * ((N * (N - 1)) // 2)
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        x = ball[i][0] - ball[j][0]
        y = ball[i][1] - ball[j][1]
        if x < 0:
            x, y = -x, -y
        elif x == 0:
            if y < 0:
                y = -y
        vector[cnt] = x * (10 ** 10) + y
        cnt += 1
C = Counter(vector)
if N == 1:
    print(1)
else:
    print(N - C.most_common()[0][1])

Solution (Python):
from collections import Counter
N = int(input())
if N == 1:
	print(1)
else:
	l = [[int(arr) for arr in input().split()] for i in range(N)]
	l.sort()
	tmp = [[b - a for a, b in zip(l[j],l[k])] for j in range(N-1) for k in range(j+1,N)]
	c = Counter(map(tuple, tmp))
	m = c.most_common(1)[0][1]
	print(N-m)

Solution (Python):
import sys
from itertools import combinations
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

class UnionFindTree:
    def __init__(self, n):
        self.nodes = list(range(n+1))
    def find(self, x):
        if self.nodes[x] == x:
            return x
        parent = self.find(self.nodes[x])
        self.nodes[x] = parent
        return parent
    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        self.nodes[a] = self.nodes[b]
    def is_same(self, a, b):
        return self.find(a) == self.find(b)


N=II()
INL=[tuple(LI()) for i in range(N)]
INL.sort()

if N == 1:
    print(1)
    exit()
elif N == 2:
    print(1)
    exit()
elif N > 2:
    res = INTMAX
    for ptr1, ptr2 in combinations(INL,2):
        union = UnionFindTree(N)
        dx, dy = ptr2[0]-ptr1[0], ptr2[1]-ptr1[1] 
        for i in range(N):
            for j in range(i, N):
                if INL[i][0] + dx == INL[j][0] and INL[i][1]+dy == INL[j][1]:
                    union.unite(i,j)
        st = set()
        for i in range(N):
            st.add(union.find(i))
        res = min(res,len(st))
    print(res)

Solution (Python):
n=int(input())
XY=[tuple(map(int,input().split())) for _ in range(n)]
XY.sort()
PQset=set()
for i in range(n):
    for j in range(i+1,n):
        p=XY[j][0]-XY[i][0]
        q=XY[j][1]-XY[i][1]
        if p!=0 or q!=0:
            PQset.add((p,q))
ans=n
for p,q in PQset:
    cost=1
    for i in range(1,n):
        x,y=XY[i]
        if (x-p,y-q) not in XY:
            cost+=1
    ans=min(cost,ans)
print(ans)

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

sys.setrecursionlimit(100000000)

class UnionFind(object):
    def __init__(self, N):
        self._parent = list(range(N))
        self.__num_components = [1] * N

    def root(self, x):
        if self._parent[x] == x:
            return x
        else:
            
            self._parent[x] = self.root(self._parent[x])
            return self._parent[x]

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

    def num_connected(self, x):
        return self.__num_components[self.root(x)]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if (x == y):
            return
        rank_x = self.__num_components[x]
        rank_y = self.__num_components[y]
        if rank_x < rank_y:
            self._parent[x] = y
            self.__num_components[y] += rank_x
        else:
            self._parent[y] = x
            self.__num_components[x] += rank_y
        return


fin = sys.stdin.readline

N = int(fin())
coordinates = [[int(elem) for elem in fin().split()] + [i] for i in range(N)]


all_dists = defaultdict(list)
for each_pair in combinations(coordinates, 2):
    each_p = each_pair[0][0]-each_pair[1][0]
    each_q = each_pair[0][1] - each_pair[1][1]
    if each_p < 0:
        each_p = -each_p
        each_q = -each_q
    if each_p * each_q == 0:
        each_p = abs(each_p)
        each_q = abs(each_q)
    each_pq = (each_p, each_q)
    all_dists[each_pq].append([each_pair[0][2], each_pair[1][2]])


count_list = []
for each_pq in all_dists:
    uf = UnionFind(N)
    for x, y in all_dists[each_pq]:
        uf.unite(x, y)
    num_distinct_components = 0
    for i in range(N):
        if uf.root(i) == i:
            num_distinct_components += 1
    count_list.append(num_distinct_components)

if len(count_list) == 0:
    print(1)
else:
    print(max(min(count_list), 1))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    n, k = LI()
    a = n - k
    if k == 1:
        print(0)
        return
    print(a)
    return


def B():
    n = II()
    xy = LIR(n)
    if n == 1:
        print(1)
        return
    ans = inf
    for i in range(n):
        for k in range(n):
            if i != k:
                b = 1
                check = []
                check.append((i,k))
                p = xy[i][0] - xy[k][0]
                q = xy[i][1] - xy[k][1]
                for l in range(n):
                    for m in range(n):
                        if not((l,m) in check) and p == xy[l][0] - xy[m][0] and q == xy[l][1] - xy[m][1]:
                            b += 1
                            check.append((l, m))
                ans = min(ans, n-b)
    print(ans)

    return


def C():
    m = II()
    a = LI()
    a.sort()
    check = [0] * m
    anslis = []
    ans = 0
    if m % 2:
        ans += a[m // 2]
        for i in range(m//2):
            anslis.append((a[i], a[-1 - i]))
            anslis.append((ans,-a[-1 - i]+a[i]))
            ans += a[-1 - i] - a[i]
    else:
        ans += a[m//2] - a[m//2-1]
        for i in range(m//2-1):
            anslis.append((a[i], a[-1 - i]))
            anslis.append((ans,-a[-1 - i]+a[i]))
            ans += a[-1 - i] - a[i]
    print(ans)
    for a, b in anslis:
        print(a,b)
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    B()

Solution (Python):
from itertools import combinations as comb

N = int(input())
xy = []
xy_ap = xy.append

for i in range(N):
    xy_ap(list(map(int, input().split())))

ls = [i for i in range(N)]

result = []

xy.sort()

for i, j in comb(ls, 2):
    result.append([xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]])

cnt = 0
for i in range(len(result)):
    if result.count(result[i]) >= cnt:
        cnt = result.count(result[i])

print(N - cnt)

Solution (Python):
N = int(input())
XY = {}
for i in range(N):
    x,y = map(int,input().split())
    XY[(x,y)] = 1
dis = {}

ans = N

for x,y in XY.keys():
    for xx,yy in XY.keys():
        if x != xx or y != yy:
            temp = (xx-x,yy-y)
            if not(temp in dis):
                dis[temp] = 1

for p,q in dis:
    test = 0
    copy = XY.copy()
    for x,y in copy:
            if (x+p,y+q) in copy.keys():
                test += 1
    if N - test < ans:
        ans = N - test
print(ans)

Solution (Python):
N = int(input())
X = []
for i in range(N):
    xi,yi = map(int,input().split())
    X.append([xi,yi])

L = []
d = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
    
        x,y = X[i][0]-X[j][0],X[i][1]-X[j][1]
        
        if not x in d:
            d[x] = {}
        if not y in d[x]:
            d[x][y] = 1
        else:
            d[x][y] += 1
m = 0
for k in list(d.keys()):
    for kk in list(d[k].keys()):
        m = max(m,d[k][kk])
print(N-m)

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

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
from collections import defaultdict

dd = defaultdict(lambda:defaultdict(bool))

X = sorted(XY)

for x,y in XY:
    dd[x][y] = True

max_count = 0
for i, (x0, y0) in enumerate(X):
    for x1, y1 in X[i+1:]:
        diff_x, diff_y = (x1-x0, y1-y0)
        counter = 0
        for x, y in X:
            if dd[x+diff_x][y+diff_y]:
                counter += 1
        max_count = max(max_count, counter)


ans = N - max_count
print(ans)

Solution (Python):
from sys import stdin
import collections

N=int(input())
xlist=[]
ylist=[]
for i in range(N):
  x, y = map(int, stdin.readline().rstrip().split())
  xlist.append(x)
  ylist.append(y)

tupleList=[]
for i in range(N):
  for j in range(N):
    if i != j:
      tupleList.append((xlist[i] - xlist[j], ylist[i] - ylist[j]))

c = collections.Counter(tupleList)

maxNum=0
for val in c.values():
  maxNum = max(maxNum, val)

print(N-maxNum)

Solution (Python):
N = int(input())
X,Y = [],[]
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
inf = 10**10

d = {}
for i in range(N):
    for j in range(i+1,N):
        if X[i] > X[j]:
            r,l = i,j
        elif X[i] == X[j]:
            if Y[i] > Y[j]:
                r,l = i,j
            else:
                r,l = j,i
        else:
            r,l = j,i
        k = (X[r]-X[l],Y[r]-Y[l])
        if k in d.keys():
            d[k] += 1
        else:
            d[k] = 1

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

Solution (Python):
import collections
import copy
import sys
N = int(input())

cost = 0
diff_list = []
x_y_list = []

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

for n in range(N):
    x, y = map(int, input().split())
    x_y_list.append((x, y))
    cost += 1

x_y_list_copy = copy.copy(x_y_list)

for n in range(N):
    x_y = x_y_list.pop()
    x = x_y[0]
    y = x_y[1]
    for tmp_x, tmp_y in x_y_list:
        diff_list.append((x - tmp_x, y - tmp_y))

for n in range(N):
    x_y = x_y_list_copy.pop(0)
    x = x_y[0]
    y = x_y[1]
    for tmp_x, tmp_y in x_y_list_copy:
        diff_list.append((x - tmp_x, y - tmp_y))

counter = collections.Counter(diff_list)
print(cost - max(counter.values()))

Solution (Python):
import sys

N = int(input())

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

coor = []
for i in range(N):
    (x,y) = (int(i) for i in input().split())
    coor.append((x,y))
    
diffs = []
for i in range(N-1):
    for j in range(i+1, N):
        diffs.append((coor[j][0]-coor[i][0], coor[j][1]-coor[i][1]))
        diffs.append((coor[i][0]-coor[j][0], coor[i][1]-coor[j][1]))

m = 1

for i in range(N*(N-1)):
    times = 0
    for j in range(N*(N-1)):
        if diffs[i] == diffs[j]:
            times += 1
    if times > m:
        m = times

ans = N - m   

print(ans)

Solution (Python):
N = list(map(int, input().split()))
d = {0:0}

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key<0:
            key=-key
        if key not in d.keys():
            d[key] = 0
        d[key] += 1
    pos.append(a)
    
print(N[0]-max(d.values()))

Solution (Python):

import sys
sys.setrecursionlimit(10000)
args = sys.stdin.readlines()
N = int(args[0])
xy_list = [[int(y) for y in x.split(' ')] for x in args[1:]]

from collections import Counter, defaultdict

delta_dict = defaultdict(int)

if N == 1:
    print(1)
    exit()
for i in range(N):
    for j in range(N):
        if i != j:
            delta_dict[(xy_list[i][0] - xy_list[j][0], xy_list[i][1] - xy_list[j][1])] += 1
    
print(N - Counter(delta_dict).most_common()[0][1])

Solution (Python):
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
data = [0] * N
if N != 1:
    for _ in range(N):
        A,B = [int(x) for x in stdin.readline().rstrip().split()]
        data[_] = (A,B)
    data=sorted(data)
    max_value = 0
    diff = []
    for j in range(0,N-1):
        for i in range(j+1,N):
            diff.append((data[j][0]-data[i][0],data[j][1]-data[i][1]))
    d=Counter(diff)
        
    print(N-max(d.values()))
else:
    print(1)

Solution (Python):
N = int(input())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))


ans = 0
res = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = items[i]
        x2, y2 = items[j]
        res.append((x1-x2, y1 -y2))

tar = []
for i in range(len(res)):
    x, y = res[i]
    cnt = 0
    for j in range(len(res)):
        if i == j:
            continue
        if x == res[j][0] and y == res[j][1]:
            cnt += 1
    if ans <= cnt:
        ans = cnt
        tar.append((x, y))


ans2 = 0
tar = list(set(tar))
for t in tar:
    cnt2 = 0
    for i in range(N):
        x, y = items[i]
        for j in range(N):
            if i == j:
                continue
            x2, y2 = items[j]
            if x - t[0] == x2 and y - t[1] == y2:
                cnt2 += 1
                break

    ans2 = max(ans2, cnt2)

print(N - ans2)

Solution (Python):


n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
if len(xy) == 1:
    print(1)
    exit()

xy.sort()
xy = xy[::-1]
aaa = []
for i in range(len(xy)-1):
    for j in range(i+1, len(xy)):
        a, b = xy[i]
        c, d = xy[j]
        aaa.append(str(a-c)+str(b-d))













import collections
bbb = collections.Counter(aaa)

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

Solution (Python):
from sys import stdin

N=int(input())
xlist=[]
ylist=[]
dict = {}
for i in range(N):
  x, y = map(int, stdin.readline().rstrip().split())
  xlist.append(x)
  ylist.append(y)

for i in range(N):
  for j in range(N):
    if i != j:
      tupleStr=str(xlist[i] - xlist[j])+","+str(ylist[i] - ylist[j])
      if tupleStr in dict:
        dict[tupleStr]+=1
      else:
        dict[tupleStr]=1

maxNum=0
for val in dict.values():
  maxNum = max(maxNum, val)

print(N-maxNum)

Solution (Python):
from collections import Counter
import sys
n=int(input())
lst=[]
for i in range(n):
  X,Y=map(int,input().split())
  lst.append([X,Y])
lst_2=sorted(lst,key=lambda x: x[0])
lst_3=sorted(lst,key=lambda x: x[1])
z=[]
if n==1:
  print(1)
  sys.exit()
else:
  for j in range(n):
    for k in range(j+1,n):
      z.append((lst_2[j][0]-lst_2[k][0],lst_2[j][1]-lst_2[k][1]))
u=[]
if n==1:
  print(1)
  sys.exit()
else:
  for j in range(n):
    for k in range(j+1,n):
      u.append((lst_3[j][0]-lst_3[k][0],lst_3[j][1]-lst_3[k][1]))
Z=Counter(z)
U=Counter(u)
m=max(Z.most_common()[0][1],U.most_common()[0][1])
print(n-m)

Solution (Python):
n = int(input())
xy_ls = []
count = 0
while count < n:
    xy_ls.append(list(map(int, input().split())))
    count = count + 1
count_diff = {}
for i in range(n):
    for j in range(n):
        x = xy_ls[i][0] - xy_ls[j][0]
        y = xy_ls[i][1] - xy_ls[j][1]
        xy = (x, y)
        if xy == (0,0):
            continue
        if count_diff.get(xy):
            count_diff[xy] += 1
        else:
            count_diff[xy] = 1
max_count = 0
for v in count_diff.values():
    if v > max_count:
        max_count = v
print(n-(int(max_count)))

Solution (Python):
import copy

n = int(input())
lst = [[0]*2 for i in range(n)]
for i in range(n):
    lst[i][0], lst[i][1] = map(int, input().split())

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

lst_copy = copy.deepcopy(lst)
saidai = 0
for i in range(n-1):
    for j in range(i+1, n):
        cnt = 0
        p = lst[j][0] - lst[i][0]
        q = lst[j][1] - lst[i][1]
        lst_copy = copy.deepcopy(lst)
        while lst_copy != []:
            xs, ys = lst_copy[0][0], lst_copy[0][1]
            lst_copy.pop(0)
            while [xs+p, ys+q] in lst_copy:
                cnt += 1
                xs, ys = xs+p, ys+q
                lst_copy.remove([xs, ys])
        saidai = max(saidai, cnt)

print(n-saidai)

Solution (Python):
from collections import Counter as c
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda xy: (xy[0], xy[1]))
if N == 1 or N == 2:
    print(1)
    exit()

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

print(N - sorted(list(c(inclination).items()), key=lambda x: x[1])[-1][1])

Solution (Python):
import sys
input = sys.stdin.readline
 
def f(_pts, p, q):
    pts = set(_pts[:])
    r = 0
 
    while len(pts) > 0:
        r += 1
        x = max(pts)
        while x in pts:
            pts.remove(x)
            x = (x[0]-p, x[1]-q)
 
    return r
 

 
n = int(input())
pts = []
for i in range(n):
    x, y = map(int, input().split())
    pts.append((x, y))
 
res = n
for i in range(len(pts)):
    for j in range(i+1, len(pts)):
        res = min(res, f(pts, -(pts[i][0]-pts[j][0]), -(pts[i][1]-pts[j][1])))
        res = min(res, f(pts, +(pts[i][0]-pts[j][0]), -(pts[i][1]-pts[j][1])))
        res = min(res, f(pts, -(pts[i][0]-pts[j][0]), +(pts[i][1]-pts[j][1])))
        res = min(res, f(pts, +(pts[i][0]-pts[j][0]), +(pts[i][1]-pts[j][1])))
 
print(res)

Solution (Python):
def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]

    ans = num
    for i in range(num):
        for j in range(num):
            if i == j:
                continue

            kyori = [data[i][0] - data[j][0], data[i][1] - data[j][1]]
            visit_list = [0 for i in range(num)]

            kari_num = 0

            for k in range(num):

                if visit_list[k]:
                    continue
                kari_num += 1
                visit_list[k] = 1
                flg = 1
                now_place = [data[k][0] + kyori[0], data[k][1] + kyori[1]]
                now_place_rev = [data[k][0] - kyori[0], data[k][1] - kyori[1]]

                while flg:
                    flg = 0
                    for l in range(num):
                        if visit_list[l]:
                            continue
                        if data[l] == now_place:
                            now_place = [now_place[0] + kyori[0], now_place[1] + kyori[1]]
                            visit_list[l] = 1
                            flg = 1
                        if data[l] == now_place_rev:
                            now_place_rev = [now_place_rev[0] - kyori[0], now_place_rev[1] - kyori[1]]
                            visit_list[l] = 1
                            flg = 1

            ans = min(ans, kari_num)




    print(ans)






if __name__ == '__main__':
    main()

Solution (Python):
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

def valid(steps):
    for i , x in enumerate(sorted(steps)):
        if i != x:
            return i - 1

    return len(steps) - 1

n = getN()
za = []
for i in range(n):
    za.append(getlist())
ans = 0
from collections import defaultdict
kumi = defaultdict(int)

for i, pa in enumerate(za):
    for j, pb in enumerate(za):
        xa, ya = pa
        xb, yb = pb
        dfx = xa - xb
        dfy = ya - yb

        diff = str(dfx) + str(dfy)
        kumi[diff] += 1

if n == 1:
    print(1)
    import sys;sys.exit()
del kumi["00"]
print(n - max(list(kumi.values())))

Solution (Python):
from sys import stdin

def solve(N, xys):
    diff = []
    diff_count = []
    idx = 0
    for i in range(N-1):
        for j in range(i+1,N):
            tmp_a = [xys[i][0] - xys[j][0], xys[i][1] - xys[j][1]]
            tmp_b = [xys[j][0] - xys[i][0], xys[j][1] - xys[i][1]]
            if tmp_a in diff:
                diff_count[diff.index(tmp_a)] += 1
            elif tmp_b in diff:
                diff_count[diff.index(tmp_b)] += 1
            else:
                diff.append(tmp_a)
                diff_count.append(1)
                idx += 1
    if diff == []:
        diff_count.append(0)
    return N - max(diff_count)

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    xys = []
    for i in range(N):
        xys.append([int(x) for x in stdin.readline().rstrip().split()])
    print(solve(N, xys))

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

dl = {}
for i in range(N):
  for j in range(N):
    dx = str(xylist[j][0] - xylist[i][0])
    dy = str(xylist[j][1] - xylist[i][1])
    l = dx + "|" + dy
    if dx == "0" and dy == "0":
      continue
    if l in dl:
      dl[l] = dl[l] + 1
    else:
      dl[l] = 1

cnt = 0
if len(dl) != 0:
  cnt = N - max(dl.values())

print(cnt if cnt > 1 else "1")

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
data = [[int(s) for s in stdin.readline().rstrip().split()] for _ in range(n)]
d = {}

for i in range(n):
  for j in range(i + 1, n):
    diff = (data[i][0] - data[j][0], data[i][1] - data[j][1])
    if diff in d:
      d[diff] += 1
    else:
      d[diff] = 1
    diff = (data[j][0] - data[i][0], data[j][1] - data[i][1])
    if diff in d:
      d[diff] += 1
    else:
      d[diff] = 1

if len(d) == 0:
  print(n)
else:
  print(n - max(d.values()))