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 copy
import random
import bisect 
import fractions 
import math
import sys
import numpy as np

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

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

xy = np.array(xy)

count_dic = {}
for i in range(N):
    for j in range(i+1,N):
        diff = xy[i] - xy[j]
        p,q = diff
        if p == 0 and q == 0:
            pass
        else:
            p = int(p)
            q = int(q)
            pq = str(p)+str(q)
            pq2 = str(-p)+str(-q)
            if pq in count_dic:
                count_dic[pq] += 1
            else:
                count_dic[pq] = 1
            if pq2 in count_dic:
                count_dic[pq2] += 1
            else:
                count_dic[pq2] = 1

ans = 1
for k,v in sorted(count_dic.items(), key = lambda x:-x[1]):
    ans = N - v
    break
print(max(1,ans))

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

if N == 1:
    print(1)
else:
    point = []
    for i in range(N):
        x,y = map(int,input().split())
        point.append([x,y])

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

    N2 = len(vec)
    check = [0 for i in range(N2)]

    for i in range(N2):
        for j in range(N2):
            minus = [-vec[j][0],-vec[j][1]]
            if vec[i] == vec[j] or vec[i] == minus:
                check[i] += 1

    print(N-max(check))

Solution (Python):
from collections import Counter
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]

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

b = sorted(a)
sb = []
for i in range(n-1):
    for j in range(i+1, n):
        sb.append((b[i][0] - b[j][0], b[i][1] - b[j][1]))
        
c = Counter(sb)
print(n-c.most_common()[0][1])

Solution (Python):
import numpy as np

n = int(input())

cnt_max = 0

if n in [1, 2]:
    output = 1
else:

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

    xy = np.array(xy)
    temp2 = []
    for i in range(n):
        temp1 = list(zip(xy[:, 0] - xy[i, 0], xy[:, 1] - xy[i, 1]))
        temp1.pop(i)
        temp2.append(temp1)
    cnt = 0
    for i in range(n):
        for j in range(n - 1):
            cnt = 0
            for k in range(n):
                
                if temp2[i][j] in temp2[k]:
                    cnt += 1
        if cnt_max < cnt:
            cnt_max = cnt

    output = n - cnt_max

print(output)

Solution (Python):
from itertools import combinations


def main():
    N = int(input())
    x = []
    y = []
    for _ in range(N):
        x_n, y_n = map(int, input().split())
        x.append(x_n)
        y.append(y_n)
    if N == 1:
        print(1)
        return
    comb = list(combinations([i for i in range(N)], 2))
    dic = {}
    for c in comb:
        i, j = c[0], c[1]
        dx = x[j] - x[i]
        dy = y[j] - y[i]
        if not (dx, dy) in dic.keys():
            dic[(dx, dy)] = 0
        if not (-dx, -dy) in dic.keys():
            dic[(-dx, -dy)] = 0
        dic[(dx, dy)] += 1
        dic[(-dx, -dy)] += 1
    dic_sorted = sorted(dic.items(), key=lambda x:x[1])[::-1]
    print(N - dic_sorted[0][1])
    return


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
B = []
for I in range(N):
    x,y = map(int,input().split())
    B.append([x,y])
B.sort()
minmin = N
for i in range(1,N):
    for j in range(N-i):
        d = [B[j+i][0]-B[j][0],B[j+i][1]-B[j][1]]
        A = [a for a in B]
        L = 1
        st = A.pop(0)
        while len(A)>0:
            next = [st[0]+d[0],st[1]+d[1]]
            if next in A:
                st = next
                A.remove(next)
            else:
                L += 1
                st = A.pop(0)
        if L < minmin:
            minmin = L
print(minmin)

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def count_cost(xy: list, p: int, q: int):
    n = len(xy)
    cnt = n

    for xi, yi in xy:
        if [xi+p, yi+q] in xy:
            cnt -= 1

    return cnt


n = ni()
xy = [list(li()) for _ in range(n)]

ans = n
for i in range(n):
    for j in range(i+1, n):
        xi, yi = xy[i]
        xj, yj = xy[j]

        p, q = xj - xi, yj - yi

        ans = min(ans, count_cost(xy, p, q))

print(ans)

Solution (Python):
import itertools
from collections import Counter
import sys
N=int(input())
balls=[]

for i in range(N):
    x,y=[int(j) for j in input().split(" ")]
    balls.append((x,y))

pqs=[]
if N==1:
    print(1)
    sys.exit()
for i in itertools.permutations(balls,2):
    p=i[1][0]-i[0][0]
    q=i[1][1]-i[0][1]
    pqs.append((p,q))

c=Counter(pqs)
c=dict(c)
c=sorted(c.items(),key=lambda w:w[1],reverse=True)
print(N-c[0][1])

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

xy = sorted(xy)
cnt = {}
if n == 1:
  ans = 1
else:
  for i in range(n-1):
    for j in range(i+1,n):
      if i == j:
        continue
      else:
        dx = xy[j][0] - xy[i][0]
        dy = xy[j][1] - xy[i][1]
        k = ','.join([str(dx), str(dy)])
        if k in cnt.keys():
          cnt[k] += 1
        else:
          cnt[k] = 1
  ans = n - max(cnt.values())
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline

N = int(readline())

XY = [list(map(int, readline().split())) for i in range(N)]

diff_list = {}

for x1, y1 in XY:
    for x2, y2 in XY:
        if x1 == x2 and y1 == y2:
            continue
        diffx = x2 - x1
        diffy = y2 - y1
        diff = (diffx, diffy)
        if not (diff in diff_list): diff_list[diff] = 0
        diff_list[diff] += 1

values = diff_list.values()
if len(values) > 0:
    m = max(values)
    ans = N - m
else:
    ans = 1

print(ans)

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

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

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())


dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

add = 1 
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)


li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    


org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)




    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""



N=int(input())
ab = [(0, 0)]*N
a = [0]*N
b = [0]*N
for n in range(N):
    ab[n] = tuple(map(int, input().split()))
    a[n] = ab[n][0]
    b[n] = ab[n][1]
    
def main(): 
    if N == 1:
        return print(1)
    XY = list(itertools.permutations(ab, 2))
    pq = []
    for xy in XY:
        pq.append((xy[0][0]-xy[1][0],xy[0][1]-xy[1][1]))
    c_pq=collections.Counter(pq)
    print(N-c_pq.most_common()[0][1])
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Solution (Python):


def readInts():
  return [int(s) for s in input().split(" ")]

def cost(N, points, pointToIndex, p, q):
  s = 0

  visited = [False for _ in range(N)]
  for i in range(N):
    if visited[i]: continue

    s += 1
    visited[i] = True

    k = 1
    while (points[i][0] + p * k <= points[-1][0]) and (points[i][1] + q * k <= points[-1][1] or points[i][1] + q * k >= points[-1][1]):
      np = (points[i][0] + p * k, points[i][1] + q * k)
      if np in pointToIndex and not visited[pointToIndex[np]]:
        visited[pointToIndex[np]] = True
        k += 1
      else:
        break

  return s

def main():
  N = readInts()[0]
  points = [tuple(readInts()) for _ in range(N)]
  points.sort()

  ans = N

  pointToIndex = {}
  for i, point in enumerate(points):
    pointToIndex[point] = i

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

  print(ans)

if __name__ == "__main__":
  main()

Solution (Python):
from collections import (
    Counter,
)


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


def _main():
    n = input_ints()[0]
    xy = [input_ints() for _ in range(n)]

    if len(xy) == 1:
        print(1)
        return

    (_, count), = Counter(
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ).most_common(1)

    print(len(xy) - count)


if __name__ == '__main__':
    _main()

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

def search(i,j):
    p = xy[i][0]-xy[j][0]
    q = xy[i][1]-xy[j][1]
    res = N
    for k in range(N):
        for l in range(N):
            if xy[k][0]-xy[l][0]==p and xy[k][1]-xy[l][1]==q:
                res -= 1
    return res

ans = N
for i in range(N):
    for j in range(N):
        if i!=j:
            ans = min(ans,search(i,j))
print(ans)

Solution (Python):

n = int(input())

points = []

defer = []

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

points.sort()

for i in range(n):
  for j in range(i+1, n):
    defer.append((points[j][0] - points[i][0], points[j][1] - points[i][1]))

maxi = 0

for d in set(defer):
  maxi = max(defer.count(d), maxi)

print(n - maxi)

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    points = [tuple(map(int, input().split())) for _ in range(N)]
    counter = Counter()

    if N == 1:
        print(1)
        return

    for i in range(N):
        for j in range(N):
            if j == i:
                continue
            a = points[i]
            b = points[j]
            dx = b[0] - a[0]
            dy = b[1] - a[1]
            counter[(dx, dy)] += 1

    vec, _ = counter.most_common()[0]
    dx, dy = vec
    visited = set()
    pointset = set(points)
    cost = 0

    for p in points:
        if p in visited:
            continue
        visited.add(p)
        x, y = p
        cost += 1

        i = 1
        while True:
            n = (x + i * dx, y + i * dy)
            i += 1
            if n in pointset:
                visited.add(n)
            else:
                break
        i = 1
        while True:
            n = (x - i * dx, y - i * dy)
            i += 1
            if n in pointset:
                visited.add(n)
            else:
                break

    print(cost)


main()

Solution (Python):
import sys
n = int(input())
arr = sorted(list(map(lambda x: tuple(map(int, x.split())), sys.stdin.readlines())))


candidate = set()
for i in range(n):
  for j in range(i+1, n):
    candidate.add((arr[j][0] - arr[i][0], arr[j][1] - arr[i][1]))
    


ans = n
for can in candidate:
  li = arr.copy()
  count = 0
  while (len(li) > 0) and (count < ans):
    count += 1
    p = li.pop(-1)
    p = (p[0] - can[0], p[1] - can[1])
    
    pos = set(li)
    while p in pos:
      pos.remove(p)
      li.remove(p)
      p = (p[0] - can[0], p[1] - can[1])
      
  ans = count
print(ans)

Solution (Python):

from copy import deepcopy
from itertools import combinations
N = int(input())
if N==1:
    print(1)
    exit()
XY = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")
for (x1, y1), (x2, y2) in combinations(XY, 2):
    p, q = (x2-x1), (y2-y1)
    XY_ = deepcopy(XY)

    
    XY_.sort(key=lambda v: (v[0]*q - v[1]*p, v[0], v[1]))
    an = 0
    xp, yp = float("inf"), float("inf")
    for x, y in XY_:
        if xp+p==x and yp+q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    
    
    ans = min(ans, an)
    for x, y in XY_:
        if xp-p==x and yp-q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    

    ans = min(ans, an)
print(ans)

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

vec_counts = {0: 0}
for x1, y1 in zip(x_list, y_list):
    for x2, y2 in zip(x_list, y_list):
        v = x1 - x2, y1 - y2
        if v != (0, 0):
            if v in vec_counts:
                vec_counts[v] += 1
            else:
                vec_counts[v] = 1

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

Solution (Python):
from collections import Counter
N = int(input())
l = []
pql = []
for i in range(N):
        x, y = map(int, input().split())
        l.append((x,y))
l.sort()
for i in range(N-1):
        for j in range(1, N-i):
                p = int(l[i+j][0] - l[i][0])
                q = int(l[i+j][1] - l[i][1])
                pql.append((p,q))
pq = Counter(pql)
cntl = pq.most_common(1)
if N == 1:
        print(1)
else:
        cnt = cntl[0][1]
        print(N - cnt)

Solution (Python):
import itertools
import numpy as np
n = int(input())
points = np.array([list(map(int,input().split())) for _ in range(n)])

if n == 1:
    print(1)
else:
    
    vectors_count = {}
    for vec1,vec2 in itertools.permutations(points,2):
        relative_vec = vec1 - vec2
        str_vec = (str(relative_vec))
        
        if str_vec in vectors_count:
            vectors_count[str_vec] += 1
        else:
            vectors_count[str_vec] = 1

    
    
    max_vec = max(vectors_count.values())
    ans = n - max_vec
    print(ans)

Solution (Python):
from collections import Counter
n = int(input())
coor = []
for i in range(n):
  x,y = map(int, input().split())
  coor.append([x,y])
  
if n == 1:
  print(1)
  exit()

dif = []
for i in range(n):
  for j in range(n):
    if i != j:
      dif.append((coor[i][0] - coor[j][0], coor[i][1] - coor[j][1]))
      
S = Counter(dif)
way = max(S.values())
print(n-way)

Solution (Python):

N = int(input())

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


vectors = []

x1, x2, y1, y2, xd, yd = 0, 0, 0, 0, 0, 0
for i in range(N):
    for j in range(i+1, N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]

        vectors.append((x1-x2, y1-y2))
        vectors.append((x2-x1, y2-y1))

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

frequencies_dic = {}
M = len(vectors)
for i in range(M):
    x, y = vectors[i]
    if (x, y) not in frequencies_dic:
        frequencies_dic[(x,y)] = 1
    else:
        frequencies_dic[(x,y)] += 1
if N == 1:
    print(1)
else:
    zeros = max(list(frequencies_dic.values()))
    ans = N - zeros
    print(ans)

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

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

from itertools import permutations
from collections import Counter
l = [((A[0]-B[0]),(A[1]-B[1])) for A,B in permutations(XY,2)]
c = Counter(l)
print(N - c.most_common()[0][1] )

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

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

XY.sort()

d={}

if N==1:
    print(1)
else:
    for i in range(N-1):
        for j in range(i+1,N):
            if str(XY[j][0]-XY[i][0])+' '+str(XY[j][1]-XY[i][1]) in d:
                d[str(XY[j][0]-XY[i][0])+' '+str(XY[j][1]-XY[i][1])]+=1
            else:
                d[str(XY[j][0]-XY[i][0])+' '+str(XY[j][1]-XY[i][1])]=1
            
    print(N-max(d.values()))

Solution (Python):
N=int(input())
xy=list(list(map(int,input().split())) for _ in range(N))
L=[]
c=1
for i in range(N):
    for j in range(N):
        if i!=j:
            L.append(([xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]]))
for l in L:
    c=max(c,L.count(l))
print(N-c if N!=1 else 1)

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


rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N = ri()
XY = []
for i in range(N):
    x,y=rl()
    XY.append((x,y))
XY.sort()
XYD = []
for i in range(N):
    x,y = XY[i]
    ret = []
    for j in range(i+1,N):
        ret.append((XY[j][0] - x, XY[j][1] - y))
    XYD.extend(ret)

import collections
c = collections.Counter(XYD).most_common()
if N == 1:
    print(1)
else:
    print(N-c[0][1])

Solution (Python):
import numpy as np
from collections import defaultdict
dic = defaultdict(int)

n = int(input())
lis = list(list(map(int, input().split())) for _ in range(n))

ans = n
ant = 0

arrx = np.zeros((n, n))
arry = np.zeros((n, n))

for i in range(n):
    for j in range(n):

        arrx[i][j] = lis[i][0] - lis[j][0]
        arry[i][j] = lis[i][1] - lis[j][1]

        dic[(arrx[i][j], arry[i][j])] += 1

        if i != j:
            if ant < dic[(arrx[i][j], arry[i][j])]:
                ant = dic[(arrx[i][j], arry[i][j])]

ans -= ant

print(ans)

Solution (Python):
import itertools

n = int(input())
balls = {i: list(map(int, input().split())) for i in range(n)}
dist_cnt = {}

for i, j in itertools.combinations(range(n), 2):
    x = balls[j][0] - balls[i][0]
    y = balls[j][1] - balls[i][1]
    
    if not x in dist_cnt.keys():
        dist_cnt[x] = {}
    if not x*(-1) in dist_cnt.keys():
        dist_cnt[x*(-1)] = {}
    if not y in dist_cnt[x].keys():
        dist_cnt[x][y] = 0
    if not y*(-1) in dist_cnt[x*(-1)].keys():
        dist_cnt[x*(-1)][y*(-1)] = 0

    dist_cnt[x][y] += 1
    dist_cnt[x*(-1)][y*(-1)] += 1
        

cnt = 0
for x, v in dist_cnt.items():
    cand = max(v.values())
    if cand > cnt:
            cnt  = cand
            
print(n - cnt)

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

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

lst = []

for i in range(n):
    for j in range(i+1,n):
        if a[j][0]-a[i][0] < 0:
            lst.append([a[i][0]-a[j][0], a[i][1]-a[j][1]])
        if a[j][0]-a[i][0] == 0:
            lst.append([a[i][0]-a[j][0], abs(a[i][1]-a[j][1])])
        else:
            lst.append([a[j][0]-a[i][0], a[j][1]-a[i][1]])

if n ==1:
    print(1)
else:
    x = 0
    for i in range(len(lst)):
        c = 1
        for j in range(i+1,len(lst)):
            if lst[i] == lst[j]:
                c += 1
        x = max(x,c)
    print(n-x)

Solution (Python):
n = int(input())
a = [tuple(map(int, input().split())) for i in range(n)]
t = set(a)
assert len(t) == len(a)
minans = 1000000000000
for i in range(n):
    for j in range(i + 1, n):
        r = t.copy()
        p = a[i][0] - a[j][0]
        q = a[i][1] - a[j][1]
        curans = 0
        while r:
            curans += 1
            m = r.pop()
            z = m
            while (m[0] + p, m[1] + q) in r:
                m = (m[0] + p, m[1] + q)
                r.remove(m)
            m = z
            while (m[0] - p, m[1] - q) in r:
                m = (m[0] - p, m[1] - q)
                r.remove(m)
        minans = min(minans, curans)
if minans == 1000000000000:
    print(1)
else:
    print(minans)

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

c = 0
if len(balls) <= 2:
    print(1)
else:
    for i in balls:
        for j in balls:
            c += 1
            if i == j:
                continue
            p[(j[0]-i[0]), j[1]-i[1]] += 1
    print(N-max(p.values()))

Solution (Python):
N=int(input())
x=['']*N
y=['']*N
dic={(0,0):0}
for i in range(N):
    x[i],y[i]=map(int,input().split())

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        else:
            p=y[j]-y[i]
            q=x[j]-x[i]
            if (p,q) in dic.keys():
                dic[(p,q)] += 1
            else:
                dic[(p,q)] = 1

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

Solution (Python):
from collections import Counter
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
c = Counter((y[0] - x[0], y[1] - x[1]) for x in a for y in a if x < y)
print(n - max(c.values(), default=0))

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

pts=[]
for i in range(n):
    pts.append(tuple(map(int,input().split())))

diffs={}
for i in range(n-1):
    for j in range(i+1,n):
        dx=pts[i][0]-pts[j][0]
        dy=pts[i][1]-pts[j][1]
        if dx<0 :
            dx=-dx
            dy=-dy
        elif dx==0 and dy<0:
            dy=-dy
        key="{},{}".format(dx,dy)
        if key in diffs:
            diffs[key]+=1
        else:
            diffs[key]=1

max=0
maxkey=""
for k,v in diffs.items():
    if v>max:
        max=v
        maxkey=k
        
print(n-max)

Solution (Python):

N = int(input())
XY = [list(map(int,input().split())) for i in range(N)]
edges = []
for i in range(N):
    x1,y1 = XY[i][0],XY[i][1]
    for j in range(N-i-1):
        J = i+j+1
        x2,y2 = XY[J][0],XY[J][1]
        dx = x2-x1
        dy = y2-y1
        if dx <= 0:
            if dx == 0:
                if dy < 0:
                    dy = -dy
            else:
                dx = -dx
                dy = -dy
        edges.append([dx,dy])

listcount = []
count = []
if N == 1:
    listcount.append([0,0])
    count.append(1)

for edge in edges:
    if edge == [0,0]:
        if [0,0] not in listcount:
            listcount.append([0,0])
            count.append(1)
    elif edge in listcount:
        count[listcount.index(edge)]+=1
    else:
        listcount.append(edge)
        count.append(1)
        
most = max(count)
if N == 1:
    print(1)
else:
    print(N-most)

Solution (Python):
import sys

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

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

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

PQ = {}
for i in range(len(XY)):
    for j in range(len(XY)):
        pq = XY[i][0] - XY[j][0], XY[i][1] - XY[j][1]
        if pq == (0, 0):
            continue
        if pq in PQ.keys():
            PQ[pq] += 1
        else:
            PQ[pq] = 1

pq = max(PQ, key=lambda x: PQ[x])
print(N - PQ[pq])

Solution (Python):
from sys import stdin
from collections import Counter

input = stdin.readline

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

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

l = []
append = l.append
for i in range(n):
  for j in range(n):
    if not i == j:
      append((xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]))
c = Counter(l)
print(n-c.most_common()[0][1])

Solution (Python):
from collections import defaultdict
from itertools import permutations
def solve():
    n = int(input())
    XY = [list(map(int, input().split())) for _ in range(n)]
    if n == 1:
        return 1
    m = defaultdict(int)
    for i, j in permutations(range(n), 2):
        m[(XY[i][0] - XY[j][0], XY[i][1] - XY[j][1])] += 1
    return n - max(m.items(), key=lambda x: x[1])[1]
print(solve())

Solution (Python):
import numpy as np
n = int(input())
if n == 1:
    print(1)
else:
    points = np.zeros((n, 2), dtype=np.int)
    for i in range(n):
        x, y = [int(x) for x in input().split()]
        points[i, 0] = x
        points[i, 1] = y

    diffs = {}
    for i in range(n):
        for j in range(n):
            if i != j:
                diff = (points[i, 0] - points[j, 0], points[i, 1] - points[j, 1])
                if diff in diffs:
                    diffs[diff] += 1
                else:
                    diffs[diff] = 1

    count = sorted(diffs.items(), key=lambda kv: kv[1])[-1][1]
    print(n-count)

Solution (Python):
def search(p,q):
  count = 0
  for i in range(n):
    for j in range(n):
      if a[i][0]-a[j][0] == p and a[i][1]-a[j][1] == q:
        count += 1
  return count
n = int(input())
a = []
for i in range(n):
  a.append(tuple(map(int,input().split())))
cc = 0
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    else:
      p = a[i][0]-a[j][0]
      q = a[i][1]-a[j][1]
      cc = max(cc,search(p,q))
print(n-cc)

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

dist_list = []
count_list = []
for i in range(N):
    for j in range(i+1, N):
        p = x[i] - x[j]
        q = y[i] - y[j]
        for index, dist in enumerate(dist_list):
            x_dist, y_dist= dist
            if (x_dist == p and y_dist == q) or (x_dist == -p and y_dist == -q):
                count_list[index] += 1
                break
        else:
            dist_list.append([p, q])
            count_list.append(1)

if N == 1:
    print(1)
else:
    print(N - max(count_list))

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())


n=int(input())
p=[]
for _ in range(n):
    p.append(tuple(intinput()))
s={}
for x,y in p:
    for x1,y1 in p:
        if x==x1 and y==y1:
            continue
        if (x-x1,y-y1) in s:
            s[(x-x1,y-y1)]+=1
        else:
            s[(x-x1,y-y1)]=1
if n==1:
    print(1)
else:
    print(n-max(s.values()))

Solution (Python):


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

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

xy.sort( key=lambda x: (x[0],x[1]) )
distmap = dict()
for i in range(n):
    xi,yi = xy[i]
    for j in range(i+1,n):
        xj, yj = xy[j]
        xd = xj - xi
        yd = yj - yi
        k = "{} {}".format(xd,yd)
        distmap[k]= distmap.get(k,0) + 1

d = max( distmap.values() )
print( n-d )

Solution (Python):
import numpy as np
import statistics
n = int(input())
x,y = [],[]
for i in range(n):
  a,b = map(int,input().split())
  x.append([a,b])
x = sorted(x, key=lambda x:(x[0],x[1]), reverse=False)
for i in range(0,n-1):
  for j in range(i+1,n):
    y.append(list(-np.array(x[i])+np.array(x[j])))
z = [y.count(i) for i in y]
if n == 1:
  print(1)
else:
  print(-max(z)+n)

Solution (Python):
n = int(input())
pos = [list(map(int, input().split())) for _ in range(n)]
d = {}
if n == 1:
  print(1)
else:
  for x, y in pos:
    for nx, ny in pos:
      dx = nx - x
      dy = ny - y
      key = (dx, dy)
      if key == (0, 0):
        continue
      if key in d:
        d[key] += 1
      else:
        d[key] = 1
  print(n - max([d[key] for key in d]))

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

xy.sort()
gap = []
gap2 = []

for i in range(len(xy)):
    for j in range(len(xy)):
        gap.append([xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]])
     
gap2 = [i for i in gap if i != [0,0]] 
gap3=[]

for i in gap2:
    if i not in gap3:
        gap3.append(i)

m = 0

for i in gap3:
    rep = gap2.count(i)
    m = max(m,rep)

print(N-m)

Solution (Python):
import itertools
if __name__=='__main__':
    N = int(input())
    x = []
    y = []
    pq = []
    max_pq = 0
    for i in range(N):
        xi, yi = map(int, input().split())
        x.append(xi)
        y.append(yi)
    for i,j in itertools.combinations(range(N),2):
        p = x[i]-x[j]
        q = y[i]-y[j]
        if p < 0:
            p = -p
            q = -q
        elif p == 0 and q < 0:
            q = -q
        pq.append((p,q))
    for k in pq:
        max_pq = max(max_pq,pq.count(k))
    print(N-max_pq)