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())
xy = [list(map(int, input().split())) for _ in range(N)]
if N == 1:
    print(1)
    exit()
xy.sort(key = lambda x:x[0])
d = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        tmp = (xy[i][0] - xy[j][0], xy[i][1] - xy[j][1])
        if not tmp in d:
            d[tmp] = 0
        d[tmp] += 1
        
    
d = sorted(d.items(), key = lambda x:-x[1])
print(N - d[0][1])

Solution (Python):
from collections import Counter

N = int(input())

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

sub = []
for x1, y1 in xys:
    for x2, y2 in xys:
        if x1 != x2 or y1 != y2:
            sub.append((x1 - x2, y1 - y2))

if not sub:
    print(1)
    exit(0)

c = Counter(sub)
m = max(c.values())

print(N - m)

Solution (Python):
from collections import defaultdict as ddict
d = ddict(int)
d[0] = 0
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort()
for i in range(n-1):
  for j in range(i+1,n):
    curx = l[j][0] - l[i][0]
    cury = l[j][1] - l[i][1]
    d[(curx,cury)] += 1
print(n-max(d.values()))

Solution (Python):
import collections


n = int(input())

l = []
for i in range(n):
    xa,ya = map(int,input().split())
    l.append([xa,ya])
if n == 1:
    print(1)
else:
    s = []
    for i in range(n):
        for k in range(i+1,n):
            xdis = l[k][0]-l[i][0]
            ydis = l[k][1]-l[i][1]
            if xdis < 0 and ydis < 0:
                xdis = xdis*(-1)
                ydis = ydis*(-1)
            if xdis < 0 and ydis == 0:
                xdis = xdis*(-1)
            if xdis < 0 and ydis >0:
                xdis = xdis*(-1)
                ydis = ydis*(-1)
            if xdis == 0 and ydis < 0:
                ydis = ydis*(-1)
            dist = (xdis,ydis)
            s.append(dist)

    

    c = collections.Counter(s)
    
    print(n - c.most_common()[0][1])

Solution (Python):
N=int(input())
data=[]
for i in range(0,N):
  a,b=map(int,input().split())
  data.append([a,b])
  


dalta_data=[]
for i in range(0,N-1): 
  Ai=data[i]
  for j in range(i+1,N): 
    Aj=data[j]
    x=Ai[0]-Aj[0]
    y=Ai[1]-Aj[1]
    dalta_data.append([x,y])
    

    
M=len(dalta_data)
maxx=0
for i in range(0,M-1):
  max1=0
  for j in range(0,M):
    if dalta_data[i]==dalta_data[j] and i!=j:
      max1=max1+1
    else:
      di=dalta_data[i]
      dj=dalta_data[j]
      if di[0]==-dj[0] and di[1]==-dj[1]:
        max1=max1+1
  if max1>maxx:
    maxx=max1
  
if N==1:
  print(1)
else:
  print(N-maxx-1)

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

if N == 1:
    print(1)
else:
    vec = []
    for i in range(N-1):
        for j in range(i+1, N):
            vec.append((balls[j][0] - balls[i][0], balls[j][1] - balls[i][1]))
    vec.sort()
    cntmax = 1
    cnt = 1
    prev = None
    for v in vec:
        if prev == v:
            cnt += 1
            cntmax = max(cnt, cntmax)
        else:
            cnt = 1
        prev = v
    print(N - cntmax)

Solution (Python):
coordinate = []
n = int(input())
cost = n
for _ in range(n):
    coordinate.append([int(i) for i in input().split()])

coordinate.sort()

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

dif.sort()

i = 0
while i < n*(n-1)/2:
    counter = dif.count(dif[i])
    cost = min(cost, n-counter)
    i += counter

print(cost)

Solution (Python):
import itertools

N=input()
if N==1:
	print 1
	quit()

XY=[ map(int, raw_input().split())  for _ in range(N) ]
XY.sort(key=lambda x:(x[0],x[1]) )

D={}

C=list( itertools.combinations( range(1,N+1), 2) )

for b1, b2 in C:
	x1=XY[b1-1][0]
	y1=XY[b1-1][1]
	x2=XY[b2-1][0]
	y2=XY[b2-1][1]

	dx=x2-x1
	dy= y2-y1
	if (dx,dy) not in D:
		D[(dx,dy)]=1
	else:
		D[(dx,dy)]+=1

print N-max( D.values() )

Solution (Python):
import queue

"""
N = int(input())



A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
P = [[int(i) for i in input().split(" ")]for _ in range(N)]

min_point = 100
for i in range(N-1):
	for j in range(i+1, N):
		p = P[i]
		q = P[j]
		if p[0] <=  q[0]:
			x = q[0]-p[0]
			y = q[1]-p[1]
			point = 0
			mp = [False for _ in range(N)]
			count = N
			index = 0
			qu = queue.Queue()
			while count:
				if not mp[index]:
					point += 1
					qu.put(P[index])
					mp[index] = True
					count -= 1
					while not qu.empty():
						top = qu.get()
						for k in range(N):
							if not mp[k] and ((top[0]-x == P[k][0] and top[1]-y == P[k][1]) or (top[0]+x == P[k][0] and top[1]+y == P[k][1])):
								count -= 1
								qu.put(P[k])
								mp[k] = True
				index += 1
			if point < min_point:
				min_point = point
if N == 1:
	min_point = 1
print(min_point)

Solution (Python):
from itertools import combinations

N = int(input())
P = {tuple(map(int, input().split())) for _ in range(N)}

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

COST = float("inf")
for a, b in combinations(P, 2):
    p = a[0] - b[0]
    q = a[1] - b[1]
    cost = 0
    for x, y in P:
        if (x + p, y + q) not in P:
            cost += 1
    COST = min(COST, cost)
print(COST)

Solution (Python):
import sys
import itertools
import collections
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = lmi()

d = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    for j in range(n):
        d[i][j] = (x[i]-x[j], y[i]-y[j])

dd = []
for i in range(n):
    dd += d[i]

c = collections.Counter(dd)
c1 = c.most_common()[0]
if c1[0] == (0,0) and n != 1:
    c1 = c.most_common()[1]
    print(n-c1[1])
else:
    print(1)

Solution (Python):
from collections import Counter
def solve(N, XY):
    if N == 1:
        return 1
    XY = sorted(XY)
    cnt = Counter()
    d = []
    for x0, y0 in XY:
        for x1, y1 in XY:
            if x0 == x1 and y0 == y1:
                continue
            d.append((x0 - x1, y0 - y1))
    m = Counter(d).most_common()[0]
    return len(XY) - m[1]

def main():
    N = int(input())

    XY = []
    for i in range(N):
        XY.append(tuple([int(x) for x in input().split()]))

    print(solve(N, XY))

main()

Solution (Python):
import collections 
N=int(input())
T=[list(map(int,input().split())) for _ in range(N)]
T.sort(reverse=True)
TMP=[]
if N==1:
    print(1)
else:
    for i in range(N-1):
        for b in range(i,N-1):
            TMP.append((T[i][0]-T[b+1][0],T[i][1]-T[b+1][1]))
    c=collections.Counter(TMP)
    print(N-c.most_common(n=1)[0][1])

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

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


counts = [[0 for _ in range(N)] for _ in range(N)]
for i, (x1, y1) in enumerate(pairs):
    for j, (x2, y2) in enumerate(pairs):
        if i == j:
            continue
        
        dx = x2 - x1
        dy = y2 - y1

        count = 0
        for x, y in pairs:
            if [x+dx, y+dy] in pairs:
                count += 1

        
        

        
        
        
        

        counts[i][j] = count





max_count = max([max(elm) for elm in counts])


out = N - max_count
print(out)

Solution (Python):
import copy
from collections import deque

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

L = []
N = int(input())
for i in range(N):
	x, y = getlist()
	L.append([x, y])

L = sorted(L)

ans = float("inf")
for i in range(N):
	for j in range(i, N):
		LL = copy.copy(L)
		Q = deque(LL)
		p = L[j][0] - L[i][0]
		q = L[j][1] - L[i][1]
		c = 1
		xx, yy = Q.popleft()

		while Q:
			if [xx + p, yy + q] in Q:
				Q.remove([xx + p, yy + q])
				xx, yy = xx + p, yy + q
			else:
				xx, yy = Q.popleft()
				c += 1

		if c < ans:
			ans = c

print(ans)

Solution (Python):







def main():
  N = int(input())
  xyn = [list(map(int, input().split())) for _ in range(N)]
  xyn = sorted(xyn, key=lambda x: x[0]+x[1])

  pats = set()
  for x1,y1 in xyn:
    for x2,y2 in xyn:
      pats.add((abs(x1-x2),abs(y1-y2)))

  ans = N
  for px,py in pats:
    visited = []
    for x,y in xyn:
      idx = -1
      for i,v in enumerate(visited):
        if abs(x-v[0])==px and abs(y-v[1])==py:
          idx = i
      if idx >= 0:
        visited.pop(idx)
      visited.append([x,y])
    ans = min(ans,len(visited))

  print(ans)
  

if __name__ == "__main__":
  main()

Solution (Python):
N = int(input())
if N == 1:
    print(1)
    exit()

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

l = {}

for i in range(N):
    for j in range(i + 1, N):
        p = x[i] - x[j]
        q = y[i] - y[j]
        if p < 0:
            p = -p
            q = -q
        if p == 0:
            q = abs(q)
        if str([p, q]) in l:
            l[str([p, q])] += 1
        else:
            l[str([p, q])] = 1

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

Solution (Python):
n = int(input())
P = [[int(x) for x in input().split()] for _ in range(n)]

diffs = [(P[j][0] - P[i][0], P[j][1] - P[i][1]) for i in range(n) for j in range(n) if i != j]

mini = 1e100
for p,q in diffs:
    if (p,q) == (0,0):
        continue
    count = n
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if (P[i][0]+p, P[i][1]+q) == (P[j][0], P[j][1]):
                count -= 1
    mini = min(count, mini)

if n == 1:
    print(1)
else:
    print(mini)

Solution (Python):
from collections import defaultdict

N = int(input())

if N == 1:
    print(1)
else:
    result = defaultdict(int)
    nodes = [tuple(map(int, input().split(' '))) for i in range(N)]
    
    for x, y in nodes:
        for i, j in nodes:
            if x == i and y == j:
                continue
            p = x - i
            q = y - j
            result[(p, q)] += 1
    max_value = max(result.values())
    print(N - max_value)

Solution (Python):
import sys
import collections

n = int(input())
xy = []
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.sort()

if len(xy) == 1:
    print(1)
    sys.exit()

cost_list = []
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        x_sub = xy[j][0] - xy[i][0]
        y_sub = xy[j][1] - xy[i][1]
        cost_list.append('{},{}'.format(x_sub, y_sub))

cost_dic = collections.Counter(cost_list)

zero_cost_num = max(cost_dic.values())

ans = n - zero_cost_num

print(ans)

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

                

d=[]
discount=[]
for i in range(n):
    for j in range(n):
        if i!=j:

            tmp=[x[i][0]-x[j][0],x[i][1]-x[j][1]]

            if tmp not in d:
                d.append(tmp)
                discount.append(1)
            else:
                discount[d.index(tmp)]+=1
     
    
if n==1:
    print(1)
else:
    print(n-max(discount))

Solution (Python):
from collections import defaultdict

table = defaultdict(lambda: 0)

n = int(input())
if (n==1):
    print(1)
elif n == 2:
    print(1)
else:
    xylist = []
    for _ in range(n):
        x, y = map(int, input().split())
        xylist += [[x, y]]

    xylist.sort()

    for i in range(n):
        for j in range(0, i):
            x = xylist[i][0] - xylist[j][0]
            y = xylist[i][1] - xylist[j][1]
            table[x+y*10**10] += 1

    max_v = max(table.values())
    print(n-max_v)

Solution (Python):
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
d = {}
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]
        if q < 0:
            p, q = -p, -q
        if q == 0:
            p = abs(p)
        d.setdefault((p, q), 0)
        d[(p, q)] += 1
m = 0
pair = (0, 0)
for x in d:
    if d.get(x, 0) > m:
        m = d.get(x, 0)
        pair = x
        
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for _ in range(n)]
    def find(self, x):
        if self.par[x] < 0:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]
    def size(self, x):
        return self.par[self.find(x)]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.size(x) < self.size(y):
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
        return 1

uf = UnionFind(n)
ans = n
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]
        if q < 0:
            p, q = -p, -q
        if q == 0:
            p = abs(p)
        if (p, q) == pair:
            ans -= uf.unite(i, j)
print(ans)

Solution (Python):
n = int(input())
if n == 1:
    print(1)
    exit()

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

res = 10 ** 100
for i in range(n):
    for j in range(i + 1, n):
        sa = []
        invalid = False
        for p,q in zip(l[i], l[j]):
            sa.append(p - q)

        cnt = 0
        flag = [False] * n
        for p in range(n):
            if not flag[p]:
                cnt += 1
            flag[p] = True
            nxt = [l[p][0] + sa[0], l[p][1] + sa[1]]
            for q in range(n):
                if l[q] == nxt:
                    if flag[q]:
                        cnt -= 1
                    else:
                        flag[q] = True
        
        
        
        
        
        
        
        
        
        
        
        
        
        
                
        
        
        
        
        
        
        
        
        
        
        res = min(res, cnt)
print(res)

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

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

if (N != 1):
    dis_dic = {}
    for n in range(N):
        for m in range(N):
            if (n != m):
                distance_tuple = (position[n][0] - position[m]
                                  [0], position[n][1] - position[m][1])

                if distance_tuple in dis_dic.keys():
                    dis_dic[distance_tuple] += 1
                else:
                    dis_dic[distance_tuple] = 1

    print(N - max(dis_dic.values()))
else:
    print(1)

Solution (Python):
n = int(input())
a = []
for i in range(n):
	x, y = map(int, input().split())
	a.append((x, y))
d = {}
if n == 1:
	print(1)
	exit()
a = sorted(a)
for i in range(n):
	tc = a[i]
	for j in range(i + 1, n):
		nd = a[j]
		x1, y1, = tc[0], tc[1]
		x2, y2, = nd[0], nd[1]
		rz1 = x1 - x2
		rz2 = y1 - y2
		d[(rz1, rz2)] = d.get((rz1,rz2), 0) + 1
print(n - max(d.values()))

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def onem():
    return int(input())
def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

n = onem()
if n == 1:
    l()
    print(1)
else:
    a = []
    for i in range(n):
        a.append(l())
    aa = []
    for i in range(n-1):
        for j in range(i,n):
            if not (a[i][0] - a[j][0] == 0 and a[i][1] - a[j][1] == 0):
                aa.append([a[i][0] - a[j][0],a[i][1] - a[j][1]])
                aa.append([a[j][0] - a[i][0],a[j][1] - a[i][1]])
    aa.sort()
    c = 1
    cc = 1
    lp = aa[0]
    for i in range(1,len(aa)):
        if lp == aa[i]:
            c += 1
        else:
            if c >= cc:
                cc = c
            lp = aa[i]
            c = 1
    if c >= cc:
        cc = c


    print(n - cc )

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

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

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

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

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


Y = set(X)
res = 0
for x in X:
    res = max(res, X.count(x))
print(N-res)

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

for i in range(n):
    for j in range(n):
        pqs.append((balls[i][0] - balls[j][0], balls[i][1] - balls[j][1]))
ans = 1 << 30
for p, q in pqs:
    tmp = 0
    if p == 0 and q == 0:continue
    for x, y in balls:
        prev = (x-p, y-q)
        if prev not in balls:
            tmp += 1
    ans = min(ans, tmp)

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
ball = sorted([list(map(int,input().split())) for i in range(n)])
diff = []
for k in range(1,n):
    for i in range(1,n):
        if i-k>=0:
            p,q = ball[i][0]-ball[i-k][0],ball[i][1]-ball[i-k][1]
            diff.append((p,q))
D = Counter(diff)
p = 0
for v in D.values():
    p = max(p,v)
print(n-p)

Solution (Python):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
if n==1:
    print(1)
    exit()
    
a = []
for i in range(n):
    x,y = inm()
    a.append((x,y))

h = defaultdict(int)
for i in range(n-1):
    z = a[i]
    for j in range(i+1,n):
        u = a[j]
        p = z[0]-u[0]
        q = z[1]-u[1]
        if p<0:
            p = -p
            q = -q
        elif p==0 and q<0:
            q = -q
        h[(p,q)] += 1

ddprint(h)
mx = max(h.values())
print(n-mx)

Solution (Python):
from collections import Counter, deque, defaultdict
from operator import itemgetter, xor, mul

import sys

from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
g0 = itemgetter(0)
N = int(input())
X, Y = [0]*N, [0]*N
P = []
for i in range(N):
    P.append(inpl())
P = sorted(P)
for i in range(N):
    X[i], Y[i] = P[i]

U = [(X[i]-X[j], Y[i] - Y[j])for i in range(N) for j in range(N) if i != j]
D = defaultdict(int)
for i in range(N):
    D[(X[i], Y[i])] = i+1

ans = N
for ux, uy in U:
    if ux < 0:
        continue
    tmp = 0
    searched = [0]*(N)
    for i in range(N):
        if not searched[i]:
            tmp += 1
            searched[i] = 1
        j = D[(X[i]+ux), (Y[i]+uy)]
        if j:
            searched[j-1] = 1
    ans = min(tmp, ans)
print(ans)

Solution (Python):
n = int(input())
xy = [[int(item) for item in input().split()] for _ in range(n)]
xy.sort()
pq = []
for x1, y1 in xy:
    for x2, y2 in xy:
        p = x1 - x2
        q = y1 - y2
        if p >= 0 and (p != 0 or q !=0):
            pq.append([p, q])
ans = n
for p, q in pq:
    val = n
    possible = {} 
    for x, y in xy:
        possible[str(x+p) + "_" + str(y+q)] = 1
    for x, y in xy:
        if str(x) + "_" + str(y) in possible:
            val -= 1
    ans = min(ans, val)
print(ans)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    p.sort()

    c = defaultdict(int)

    for i in range(n):
        for j in range(i):
            c[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += 1

    print((n - max(c.values())) if c else 1)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

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

xys.sort()
diffs = []
count = []

for i in range(N):
    for j in range(i+1,N):
        x1,y1 = xys[i]
        x2,y2 = xys[j]
        diff = (x1-x2, y1-y2)
        if diff not in diffs:
            diffs.append(diff)
            count.append(1)
        else:
            k = diffs.index(diff)
            count[k] += 1
if N == 1:
    print(1)
else:
    print(N-max(count))

Solution (Python):

 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 
import time
import sys
from pprint import pprint

N = int(input())
P = []
for _i in range(N):
    P.append([ int(x) for x in input().split() ])

diff = defaultdict(int)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        key = "{} - {}".format(P[i][0]-P[j][0], P[i][1]-P[j][1])
        diff[key] += 1

if N == 1:
    print(1)
else:
    key = max(diff.keys(), key=lambda x: diff[x])
    print(N-diff[key])

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

case = [N]
for x,y in xy:
    for xx, yy in xy:
        if x == xx and y == yy:
            continue
        score = N
        xs = xx - x
        ys = yy - y
        for xxx,yyy in xy:
            if x == xxx and y == yyy:
                continue
            if (xxx - xs,yyy - ys) in xy:
                score -= 1
        case.append(score)
print(min(case))

Solution (Python):

import sys


def solve(N: int, x: "List[int]", y: "List[int]"):
    diffs = []
    for i in range(N):
        for j in range(i + 1, N):
            diffs.append([x[j] - x[i], y[j] - y[i]])
            diffs.append([x[i] - x[j], y[i] - y[j]])
    diffs.sort()
    cnt = 0
    tmp = 1
    for i in range(1, len(diffs)):
        if diffs[i] == diffs[i - 1]:
            tmp += 1
        else:
            cnt = max(tmp, cnt)
            tmp = 1
    ret = N - cnt
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = [int()] * (N)  
    y = [int()] * (N)  
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
dc = {}

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

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

mxv = 0
mxk = None
for key, value in dc.items():
    if value > mxv:
        mxv = value
        mxk = key

print(n - mxv)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
import collections
import itertools

INF = 10 ** 10



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

data = []

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

for i in range(N):
    for j in range(i+1, N):
        x_diff = xy[i][0] - xy[j][0]
        y_diff = xy[i][1] - xy[j][1]
        data.append("{0},{1}".format(x_diff, y_diff))
        data.append("{0},{1}".format(-x_diff, -y_diff))

c = collections.Counter(data)

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

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

if N ==1:
    print(1)
else:
    pqlis = []
    lis.sort()
    dxdic ={}
    for i in range(N):
        for j in range(i):
            dx = lis[i][0] -lis[j][0]
            if dx in dxdic.keys():
                dxdic[dx].append([i,j])
            else:
                dxdic[dx] =[[i,j]]
    ans = 0
    for li in dxdic.values():
        foo = 0
        dydic = {}
        for i,j in li:
            dy = lis[i][1] -lis[j][1]
            if dy in dydic.keys():
                dydic[dy] += 1
            else:
                dydic[dy] = 1
        foo = max(dydic.values())
        if ans < foo:
            ans = foo
    print(N-ans)

Solution (Python):
points=[]
N=int(input())
dic={}
for _ in range(N):
    a,b=list(map(int,input().strip().split(' ')))
    points+=[(a,b)]

points=sorted(points)
for i in range(len(points)):
    dic[points[i]]=i

def find(points):
    diff={}
    for i in range(len(points)):
        for j in range(i+1,len(points)):
            a=points[j][0]-points[i][0]
            b=points[j][1]-points[i][1]
            if a!=0 or b!=0:
                diff[(a,b)]=1
    
    return diff

diff=find(points)

def find(X):
    a,b=X
    checked=[0]*len(points)
    ans=0
    for i in range(len(checked)):
        if checked[i]==0:
            ans+=1
            x,y=points[i]
            for j in range(1,len(checked)+1):
                temp_x,temp_y=x+a*j,y+b*j
                if (temp_x,temp_y) in dic:
                    order=dic[(temp_x,temp_y)]
                    checked[order]=1
                else:
                    break
    return ans

ANS=len(points)

for X in diff:
    ANS=min(ANS,find(X))
print(ANS)

Solution (Python):
n=int(input())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
lpq=[]
for i in range(n):
  for j in range(n):
    if i==j:
      pass
    else:
      lpq.append([l[i][0]-l[j][0],l[i][1]-l[j][1]])
score=n-1
for i in lpq:
  s1=0
  for j in l:
    for k in l:
      if j==k:
        pass
      else:
        if j[0]-k[0]==i[0] and j[1]-k[1]==i[1]:
          s1+=1
  s=n-s1
  if s<score:
    score=s
if n==1:
  print(1)
else:
  print(score)

Solution (Python):


def f(N, XY):
    S = set(XY)
    sc = N

    for i in range(N):
        x0, y0 = XY[i]

        for j in range(i+1, N):
            x1, y1 = XY[j]

            sc = min(sc, N - g(S, x1-x0, y1-y0))

    return sc


def g(S, p, q):
    cnt = 0

    for x,y in S:
        if (x+p, y+q) in S:
            cnt += 1

    return cnt
            
    


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

    print(f(N, XY))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
from collections import defaultdict
from functools import reduce
from itertools import permutations


n = int(input())



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

res = n

for n1, n2 in permutations(range(n) ,2):
    p = lis[n1][0] - lis[n2][0]
    q = lis[n1][1] - lis[n2][1]
    s = set(range(n))
    s.remove(n1)
    s.remove(n2)

    score = 1
    x = lis[n1][0]
    y = lis[n1][1]

    while True:
        x2 = x
        y2 = y
        while True:
            if ((x2+p), (y2+q)) in dic:
                i = dic[((x2+p), (y2+q))]
                if i in s:
                    s.remove(i)
                x2 = lis[i][0]
                y2 = lis[i][1]
            else:
                break
        x2 = x
        y2 = y
        while True:
            if ((x2-p), (y2-q)) in dic:
                i = dic[((x2-p), (y2-q))]
                if i in s:
                    s.remove(i)
                x2 = lis[i][0]
                y2 = lis[i][1]
            else:
                break

        if len(s) == 0:
            break
        i = s.pop()
        x = lis[i][0]
        y = lis[i][1]
        score += 1
    res = min(res, score)
print(res)