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 itertools, collections
N = int(input())
XY = sorted([[int(_) for _ in input().split()] for _ in range(N)])
count = collections.defaultdict(int)
for i, j in itertools.combinations(range(N), 2):
    x1, y1 = XY[i]
    x2, y2 = XY[j]
    count[y2 - y1 + (x2 - x1) * 10**10] += 1
if count:
    print(N - max(count.values()))
else:
    print(1)

Solution (Python):
from collections import Counter
n = int(input())

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

l = []
for i in range(n):
    pre = [x[i], y[i]]
    for j in range(n):
        if i == j:
            continue
        l.append("{}_{}".format(x[j] - pre[0], y[j] - pre[1]))

if len(l) > 0:
    c = Counter(l)
    a = int(c.most_common()[0][1])
    print(n - a)
else:
    print(1)

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        p = xy[j][0]-xy[i][0]
        q = xy[j][1]-xy[i][1]
        merge = 0
        for k in range(N):
            if [xy[k][0]+p, xy[k][1]+q] in xy:
                merge += 1
        ans = max(ans, merge)
print(N-ans)

Solution (Python):
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
x, y = [], []
for i, j in xy:
    x += [i]
    y += [j]
memo = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[j] - x[i]
        q = y[j] - y[i]
        pq = str(i) + '_' + str(j)
        for k in range(N):
            for l in range(N):
                if k == l:
                    continue
                if (x[k] - x[l]) == p and (y[k] - y[l]) == q:
                    if pq in memo:
                        memo[pq] += 1
                    else:
                        memo[pq] = 1
if N != 1:
    print(N-max(memo.values()))
else:
    print('1')

Solution (Python):
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
x, y = [], []
for i, j in xy:
    x += [i]
    y += [j]
ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[j] - x[i]
        q = y[j] - y[i]
        c = 0
        for k in range(N):
            for l in range(N):
                if k == l:
                    continue
                if (x[k] - x[l]) == p and (y[k] - y[l]) == q:
                    c += 1
        ans = max(ans, c)
if N != 1:
    print(N-ans)
else:
    print('1')

Solution (Python):
import itertools
from collections import Counter

def main():
    N = int(input())
    data = []
    common_data = []
    max_common_num = 0
    for _ in range(N):
        data.append( list(map(int, input().split())) )

    data.sort()

    if N == 1:
        return 1
    else:
        for obj in itertools.combinations(data, 2):
            
            common_data.append( str(obj[0][0] - obj[1][0]) + "_" + str(obj[0][1] - obj[1][1]) )

        
        counter = Counter(common_data)
        for word, cnt in counter.most_common():
            if cnt >= max_common_num:
                max_common_num = cnt

    
    return N - max_common_num

if __name__ == '__main__':
    print( main() )

Solution (Python):
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
 
N = int(input())
xy = []
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
xy.sort()

edges = defaultdict(int)
edges[(0,0)] = 0
for i in range(N):
    for j in range(i+1,N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        p, q = x2-x1, y2-y1
        edges[(p,q)] += 1
 
print(N - max(edges.values()))

Solution (Python):

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

m = 0
for i, j in product(range(n), repeat=2):
    if i == j:
        continue
    p = x[j] - x[i]
    q = y[j] - y[i]
    c = 0
    for s, t in product(range(n), repeat=2):
        if s == t:
            continue
        if x[t] - x[s] == p and y[t] - y[s] == q:
            c += 1
    m = max(m, c)

print(n - m)

Solution (Python):
N = int(input())
arr = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = {}
for i in range(N):
    for j in range(i+1,N):
        pq = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt.setdefault(pq, 0)
        cnt[pq] += 1
print(1 if cnt == {} else N - max(cnt.values()))

Solution (Python):
import sys

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

    if n <= 2:
        print(1)
        sys.exit()

    w = [tuple(map(int,input().split())) for x in range(n)]
    w.sort()

    pqs = {}
    for i in range(n-1):
        for j in range(i+1,n):
            xy = (w[j][0] - w[i][0], w[j][1] - w[i][1])
            if xy not in pqs:
                pqs[xy] = 1
            else:
                pqs[xy] += 1
    print(n - max(pqs.values()))

if __name__=='__main__':
    main()

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def mod_inv(x):
    
    global mod
    return pow(x, mod - 2, mod)


def gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    xylist = intinl(n)

    pqtoij = defaultdict(list)

    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            x1, y1 = xylist[i]
            x2, y2 = xylist[j]

            p = x1 - x2
            q = y1 - y2

            pqtoij[(p, q)].append((i, j))

    maxcount = 0

    for (p, q), ijlist in pqtoij.items():
        maxcount = max(maxcount, len(ijlist))

    print(n - maxcount)


if __name__ == '__main__':
    main()

Solution (Python):
def b_picking_up(N, Positions):
    if N == 1:
        return 1  

    from collections import defaultdict
    difference_count = defaultdict(int)  

    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            
            diff_x = Positions[j][0] - Positions[i][0]
            diff_y = Positions[j][1] - Positions[i][1]
            difference_count[(diff_x, diff_y)] += 1
    return N - max(difference_count.values())  

N = int(input())
Positions = [[int(i) for i in input().split()] for j in range(N)]
print(b_picking_up(N, Positions))

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


n = int(input())
balls = []

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

if n == 1:
    print(1)
else:
    counter = Counter()
    for b1, b2 in permutations(balls, 2):
        p, q = b1[0] - b2[0], b1[1] - b2[1]
        counter[(p, q)] += 1

    (p, q), val = counter.most_common(1)[0]
    print(n - val)

Solution (Python):
def main():
    n = int(input())
    if n ==1:
        print(1)
        exit()
    x_y_list = []
    p_q_dic = {}
    for i in range(n):
        x,y = map(int,input().split(' '))
        x_y_list.append((x,y))
    for i in range(n):
        x_i = x_y_list[i][0]
        y_i = x_y_list[i][1]
        for j in range(n):
            if i == j:
                continue
            x_j = x_y_list[j][0]
            y_j = x_y_list[j][1]
            p = x_j - x_i
            q = y_j - y_i
            if (p !=0 or q !=0) and (p,q) in p_q_dic:
                p_q_dic[(p,q)] += 1
            elif p != 0 or q != 0:
                p_q_dic[(p,q)] = 1
    p_q_sorted = sorted(p_q_dic.values(),reverse=True)
    print(n-p_q_sorted[0])

main()

Solution (Python):
import collections
N = int(input())
if N == 1:
  print(1)
elif N == 2:
  print(1)
else:
  ball = [tuple(map(int, input().split())) for _ in range(N)]
  ball.sort(key=lambda x:(x[0], x[1]))
  diff = [tuple((ball[i][0] - ball[j][0], ball[i][1] - ball[j][1])) for i in range(N) for j in range(i + 1, N)]
  c = collections.Counter(diff)
  ans = c.most_common()[0][1]
  print(N - ans)

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

import itertools
import collections

if N==1:
    print(1)
    
else:
    arr = list(itertools.combinations(List, 2))
    vec1 = []
    vec2 = []
    for i in range(len(arr)):
        vec1.append([arr[i][1][0]-arr[i][0][0], arr[i][1][1]-arr[i][0][1]])
        vec2.append([arr[i][0][0]-arr[i][1][0], arr[i][0][1]-arr[i][1][1]])
        
    vec = vec1+vec2
    counter = collections.Counter(map(tuple, vec))
    
    v =  counter.most_common(1)[0][0]
    num = counter.most_common(1)[0][1]
    
    print(N-num)

Solution (Python):
N = int(input())
XY = sorted([tuple(map(int, input().split())) for _ in range(N)])
PQ = []
for i in range(N):
    for j in range(i+1, N):
        PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1]))

ans = N
for p, q in PQ:
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            if XY[j][0] - p == XY[i][0] and XY[j][1] - q == XY[i][1]:
                cnt += 1
    ans = min(ans, N-cnt)
print(ans)

Solution (Python):
import collections

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

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

pq = []
cost = N

for xyi in xy:
    for xyj in xy:
        pq.append((xyi[0]-xyj[0], xyi[1]-xyj[1]))

count = collections.Counter(pq)
if (count.most_common()[0][0] == (0,0)):
    print(N - count.most_common()[1][1])
else:
    print(N - count.most_common()[0][1])

Solution (Python):



N = int(input())
S = []
for _ in range(N):
    x, y = map(int, input().split())
    S.append([x, y])
cost = N
d = {}

if N==1:
    print(1)
    exit()
for l,le in enumerate(S):
    for m, me in enumerate(S):
        if l == m:
            continue
        t = (me[0] - le[0], me[1] - le[1])
        if t in d:
            d[t] +=1
        else:
            d[t] = 1

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

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):
from collections import defaultdict
n=int(input())
o=[]
for i in range(n):
    x,y=map(int,input().split())
    o.append([x,y])
o.sort()
p2=[]
q2=[]
c=[]
if n==1:
    print(1)
else:
    for i in range(n):
        for j in range(i+1,n):
            p2=o[j][0]-o[i][0]
            q2=o[j][1]-o[i][1]
            c.append(str(p2)+" "+str(q2))
    r=defaultdict(int)
    for f in c:
        r[f]+=1
    p=list(r.values())
    q=max(p)
    print(n-q)

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

d = {}
x = [0] * N
y = [0] * N
from collections import defaultdict
for i in range(N):
    x[i], y[i] = map(int, input().split())

d = defaultdict(int)
for i in range(N):
    for j in range(N):
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        if i == j:
            continue
        d[(dx, dy)] += 1
        
if N == 1:
    print(1)
else:
    print(N - max(d.values()))

Solution (Python):
import itertools
n=int(input())
ball=[]
for i in range(n):
    ball.append([int(i) for i in input().split()])

ball.sort()


pq_cand=set()
for v in itertools.combinations(ball,2):
    xdiff=v[0][0]-v[1][0]
    ydiff=v[0][1]-v[1][1]
    pq_cand.add((xdiff,ydiff))
    
cost=n
for pq in pq_cand:
    cost_tmp=0
    for point in ball:
        if [point[0]+pq[0],point[1]+pq[1]] not in ball:
            cost_tmp+=1
    cost=min(cost,cost_tmp)
print(cost)

Solution (Python):


from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
ls = []
for loop in range(N):
	x, y = map(int, raw_input().split())
	ls += [(x, y)]
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		dx = ls[i][0] - ls[j][0]
		dy = ls[i][1] - ls[j][1]
		cnt = 0
		for k in range(N):
			for l in range(N):
				if ls[k][0] - ls[l][0] == dx and ls[k][1] - ls[l][1] == dy:
					cnt += 1
		ans = max(cnt, ans)
print N - ans

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

if N==1:
    print(1)
    exit(0)
xy_list.sort(key=lambda x:x[1]) 
xy_list.sort(key=lambda x:x[0]) 


for i in range(N):
  for j in range(N):
    if( i==j ):     
      continue
    t = (xy_list[i][0]-xy_list[j][0],xy_list[i][1]-xy_list[j][1])
    ans.append(t)
    

res = [ans.count(e) for e in set(ans)]

print(N-max(res))

Solution (Python):


from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
ls = []
for loop in range(N):
	x, y = map(int, raw_input().split())
	ls += [(x, y)]
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		dx = ls[i][0] - ls[j][0]
		dy = ls[i][1] - ls[j][1]
		cnt = 0
		for k in range(N):
			for l in range(N):
				if ls[k][0] - ls[l][0] == dx and ls[k][1] - ls[l][1] == dy:
					cnt += 1
		ans = max(cnt, ans)
print N - ans

Solution (Python):
n = int(input())
arr = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}

if n == 1:
  print(1)
  exit()
  
for i in range(n):
  for j in range(i+1, n):
    x = (arr[j][0]-arr[i][0], arr[j][1]-arr[i][1])
    if x in d:
      d[x] += 1
    else:
      d[x] = 1

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

Solution (Python):

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

for i in range(N):

    newxy = list(map(int,input().split()))
    xy.append(newxy)

ans = -1
now = 0

for i in range(N):

    for j in range(i):

        now = 0

        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]


        
        

        xydic = {}

        for k in xy:

            if str(k) in xydic:

                continue
                

            else:

                now += 1

                xydic[str(k)] = 1

                

                plbul = True

                cnt = 1
                while plbul:

                    if [ k[0] + cnt * p , k[1] + cnt * q ] in xy :

                        xydic [str([k[0] + cnt * p , k[1] + cnt * q])] = 1
                        
                        cnt += 1

                    else:
                        plbul = False

                cnt = -1

                plbul = True
                
                while plbul:

                    if [ k[0] + cnt * p , k[1] + cnt * q ] in xy :

                        xydic [str([k[0] + cnt * p , k[1] + cnt * q])] = 1
                        
                        cnt -= 1

                    else:
                        plbul = False

                

                                
        if now < ans or ans < 0:
            ans = now
            

if N == 1:
    ans = 1

print (ans)

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

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

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

X.sort()
diff = []
for i, j in combinations(range(N), 2):
    diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1]))
print(N - Counter(diff).most_common()[0][1])

Solution (Python):











import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():

    N = I()
    XY = LLIN(N)
    XY.sort()
    if N == 1:
        print(1)
        exit()
    
    count = defaultdict(int)
    for i, (x1, y1) in enumerate(XY):
        for j, (x2, y2) in enumerate(XY[i+1:]):
            dx, dy = x1 - x2, y1 - y2
            count[(dx, dy)] += 1
    print(N - max(count.values()))
    
    
                        
if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
from collections import defaultdict
from copy import copy
N = int(input())
XY = list(sorted([tuple(map(int, input().split())) for _ in range(N)]))
PQ = []
for i in range(N-1):
    for j in range(i, N):
        PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1]))
PQ = list(set(PQ))
ans = N
for p, q in PQ:
    tmp1 = 1
    T = deque(copy(XY))
    x, y = T.popleft()
    cnt = 1
    while cnt < N:
        tmp2 = 1
        for s, t in T:
            if s - p == x and t - q == y:
                tmp2 = 0
                break
        if tmp2:
            x, y = T.popleft()
        else:
            T.remove((s, t))
            x, y = s, t
        tmp1 += tmp2
        cnt += 1      
    ans = min(ans, tmp1)
print(ans)

Solution (Python):
n = int(input())
point = []
for i in range(n):
    x_, y_ = map(int, input().split())
    point.append([x_, y_])

point.sort(key=lambda x: x[1])
point.sort(key=lambda x: x[0])
ans = 0
x = []
y = []
for i in range(n):
    x.append(point[i][0])
    y.append(point[i][1])

for i in range(n):
    for j in range(i+1, n):
        count = 0
        p = x[j] - x[i]
        q = y[j] - y[i]
        for k in range(n):
            for l in range(k+1, n):
                if (x[l] - x[k] == p) and (y[l] - y[k] == q):
                    count += 1
        ans = max(ans, count)

print(n - ans)

Solution (Python):


import sys
N = int(input())
x = [0]*N
y = [0]*N
kouholist = []
ans = N
if N == 1:
    print(1)
    sys.exit()

for i in range(N):
    x[i], y[i] = map(int, input().split())
for m in range(N):
    for p in range(N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = N
        for r in range(N):
            for q in range(N):
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari -= 1
        if ans_kari < ans:
            ans = ans_kari

print("{}".format(ans))

Solution (Python):











import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():

    N = I()
    XY = LLIN(N)
    if N == 1:
        print(1)
        exit()
    XY.sort()

    count = defaultdict(int)
    for i, (x1, y1) in enumerate(XY):
        for j, (x2, y2) in enumerate(XY[i+1:]):
            dx, dy = x1 - x2, y1 - y2
            count[(dx, dy)] += 1
    maxim = -inf
    for v in count.values():
        maxim = max(maxim, v)
    print(N - maxim)
    
    
                        
if __name__ == '__main__':
    main()

Solution (Python):
import itertools
n=int(input())
ball=[]
for i in range(n):
    ball.append([int(i) for i in input().split()])

ball.sort()


pq_cand=set()
for v in itertools.combinations(ball,2):
    xdiff=v[0][0]-v[1][0]
    ydiff=v[0][1]-v[1][1]
    pq_cand.add((xdiff,ydiff))
    
connect=0
for pq in pq_cand:
    con=0
    for point in ball:
        if [point[0]+pq[0],point[1]+pq[1]] in ball:
            con+=1
    connect=max(connect,con)
print(n-connect)

Solution (Python):
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
xy.sort()
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    for j in range(i+1,N):
        tmp = (xy[j][0]-xy[i][0],xy[j][1]-xy[i][1])
        d[tmp] += 1
if N == 1:
    print(1)
else:
    print(N-max(d.values()))

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

xy.sort()
if n == 1:
    print(1)
    exit()
ans = 10**7

for i in range(n-1):
    for j in range(i+1, n):
        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]
        a = 0
        for k in range(n):
            if [xy[k][0] - p, xy[k][1] - q] not in xy:
                a += 1
        ans = min(a, ans)

print(ans)

Solution (Python):
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
pq = {}

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

for (x, y) in xy:
    for (a, b) in xy:
        if (x, y) != (a, b):
            if (x-a, y-b) in pq.keys():
                pq[(x-a, y-b)] = pq[(x-a, y-b)] + 1
            else:
                pq[(x-a, y-b)] = 1

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

Solution (Python):
n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i, j in arr:
    for k, l in arr:
        if (i, j) == (k, l):
            continue
        dif = (k - i, l - j)
        cnt.setdefault(dif, 0)
        cnt[dif] += 1
print(n - max(cnt.values(), default=0))

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

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

ans=0
for i in range(0,N-1):
  for j in range(i+1,N):
    sax = balls[j][0]-balls[i][0]
    say = balls[j][1]-balls[i][1]
    merge=0
    for k in range(0,N):
      if([balls[k][0]+sax,balls[k][1]+say] in balls):
          merge+=1
    ans=max(ans,merge)
print(N-ans)

Solution (Python):
from collections import Counter
N = int(input())
XY = []
XY_cand = []
for _ in range(N):
        x, y = map(int, input().split())
        XY.append((x,y))
for (x, y) in XY:
        for (i, j) in XY:
                if i != x or j != y:
                        XY_cand.append((i-x, j-y))
if XY_cand == []:
        print(N)
else:
        print(N - Counter(XY_cand).most_common()[0][1])

Solution (Python):

import sys
def p(*a):
  s=" ".join(map(str,a))
  
  sys.stderr.write(s+"\n")


N = int(input())						

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

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




from itertools import permutations
from itertools import combinations
L = list(combinations(P, 2))



A=[]

for l in L:
	a=l[1][0]-l[0][0]
	b=l[1][1]-l[0][1]
	if a<0:
		a,b=-a,-b
	if a==0 and b<0:
		b=-b
	A.append((a,b))





from collections import defaultdict

d = defaultdict(int)
for b in A:
	d[b] += 1





B=[]
for k, v in sorted(d.items(), key=lambda x: -x[1]):
	
	break



print(N-v)

Solution (Python):
n=int(input())
if n==1:
	print(1)
	exit()
xy = sorted([list(map(int,input().split())) for i in range(n)])
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):
		p = xy[j][0]-xy[i][0]
		q = xy[j][1]-xy[i][1]
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))

Solution (Python):
import numpy as np

def main():
    n = int(input())
    ball = [list(map(int, input().split(' '))) for i in range(n)]
    ball = np.array(ball, dtype=int)
    if n == 1:
        print(1)
        exit()

    l1 = []
    for i in range(len(ball)):
        for j in range(len(ball)):
            if i == j: continue
            dis1 = ball[i] - ball[j]
            l1.append(list(dis1))

    c1 = []
    for i in range(len(l1)):
        c1.append(l1.count(l1[i]))
    m1 = np.max(np.array(c1, dtype=int))

    print(n-m1)

if __name__ == "__main__":
    main()

Solution (Python):







import sys
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
from collections import defaultdict

nb_points = RI()
points    = [RMI() for _ in range(nb_points)]
if nb_points == 1:
    print(1)
else:
    pq = defaultdict(int)
    for i in range(nb_points):
        for j in range(nb_points):
            if i == j : continue
            p1 = points[i][0] - points[j][0]
            q1 = points[i][1] - points[j][1]
            pq[(p1, q1)]  = pq.get((p1, q1), 0) + 1
    print(nb_points - max(pq.values()))

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

ans = float("inf")

if N < 3:
  ans = 1
else:   
  for i in range(N):
    x, y = xy[i][0], xy[i][1]
    for j in range(N):
      if i == j:
        continue
      p, q = xy[j][0] - x, xy[j][1] - y
      cnt = 0
      for k in range(N):
        xk, yk = xy[k][0], xy[k][1]
        for l in range(N):
          if k == l:
            continue
          if xy[l][0] - xk == p and xy[l][1] - yk == q:
            cnt += 1
      ans = min(ans, N - cnt)
print(ans)

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

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

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

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

for i in range(n):
    for j in range(n):
        if( i==j ):
            continue
        t = (xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
        ans.append(t)

res = [ans.count(e) for e in set(ans)]
print(n-max(res))

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

ans = float("inf")

if N < 3:
  ans = 1
else:   
  for i in range(N):
    x, y = xy[i][0], xy[i][1]
    for j in range(N):
      if i == j:
        continue
      p, q = xy[j][0] - x, xy[j][1] - y
      cnt = 0
      for k in range(N):
        xk, yk = xy[k][0], xy[k][1]
        for l in range(N):
          if k == l:
            continue
          if xy[l][0] - xk == p and xy[l][1] - yk == q:
            cnt += 1
      ans = min(ans, N - cnt)
print(ans)

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

def func(p,q):
    flag = [0]*n
    for i in range(n):
        for j in range(n):
            if i==j or flag[j-1]==1:
                continue
            if xy[j][0]-xy[i][0]==p and xy[j][1]-xy[i][1]==q:
                flag[j-1]=1
    return n-sum(flag)

ans = n
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        ans = min(ans,func(xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]))
print(ans)