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



Sample input:
2
1 1
2 2


Sample output:
1

Submission status: Accepted

Solution code:
N = int(input())
List=[list(map(int,input().split())) for i in range(N)]
A = []
b =[]
for i in range(N):
    for j in range(i):
        if List[i][0] > List[j][0]:
            a = [List[i][0]-List[j][0],List[i][1]-List[j][1]]
        elif List[i][0] < List[j][0]:
            a = [List[j][0]-List[i][0],List[j][1]-List[i][1]]
        else:
            if List[i][1] > List[j][1]:
                a = [List[i][0]-List[j][0],List[i][1]-List[j][1]]
            elif List[i][1] < List[j][1]:
                a = [List[j][0]-List[i][0],List[j][1]-List[i][1]]
        b.append(A.count(a))
        A.append(a)
if b == []:
    print(1)
else:
    print(N-max(b)-1)

Submission status: Accepted

Solution code:
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])

PQ = {}

for i in range(N):
    x0, y0 = XY[i]
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[j]
        p, q = x0 - x1, y0 - y1
        key = str(p) + ',' + str(q)
        if key in PQ:
            PQ[key] += 1
        else:
            PQ[key] = 1
ansL = PQ.values()
print(N - max(list(ansL)))

Submission status: Accepted

Solution code:
import sys
def cul(p,q):
    tmp=0
    for i in range(1,N):
        for j in range(i):
            tmpp,tmpq=a[i][0]-a[j][0],a[i][1]-a[j][1]
            if tmpp==p and tmpq==q: tmp+=1
            elif tmpp==-p and tmpq==-q: tmp+=1
    return N-tmp

N=int(input())
if N==1: print(1),sys.exit()
ans=100

a=[list(map(int,input().split())) for i in range(N)]
for i in range(1,N):
    for j in range(i):
        p,q=a[i][0]-a[j][0],a[i][1]-a[j][1]
        ans=min(ans,cul(p,q))
    
print(ans)

Submission status: Accepted

Solution code:
import itertools


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

  if n == 1:
    print(1)
    return

  for i, j in itertools.product(range(len(p)), repeat=2):
    if i == j:
      continue

    d = (p[j][0] - p[i][0], p[j][1] - p[i][1])

    if d not in c:
      c[d] = 1
    else:
      c[d] += 1

  print(len(p) - max(c.values()))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from copy import *
from collections import*
n=int(input())
if n==1:
    print(1)
    exit()
p=[list(map(int,input().split()))for i in range(n)]
l=[]
for i in range(n):
    q=deepcopy(p)
    a,b=q.pop(i)
#    print(a,q)
    l.extend([(s-a,t-b)for s,t in q])
print(n-(Counter(l).most_common()[0][1]+1)+1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7


import collections
import itertools
import operator


class UnionFind:
    def __init__(self, elems=None):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)

        if elems is not None:
            for elem in elems:
                _, _ = self.parent[elem], self.rank[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

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

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]


def main(): 
    N = II()
    position = []
    for _ in range(N):
        position.append(LI())

    min_ = INF
    import itertools
    for A, B in itertools.combinations(range(N), 2):
        uf = UnionFind(range(N))
        p = position[A][0] - position[B][0]
        q = position[A][1] - position[B][1]
        # print(p,q)
        uf.unite(A, B)
        for X, Y in itertools.combinations(range(N), 2):
            if A == X and B == Y:
                continue
            if (p == position[X][0] - position[Y][0] and q == position[X][1] - position[Y][1]) or (p == position[Y][0] - position[X][0] and q == position[Y][1] - position[X][1]):
                uf.unite(X, Y)
        
        min_ = min(min_, len(list(uf.grouper())))
    print(1 if N == 1 else min_)

main()

Submission status: Accepted

Solution code:
import collections
n=int(input())
xy=[]
for i in range(n):
    xy.append(list(map(int,input().split())))
dif=[]
for i in range(n):
    for k in range(i+1,n):
        dif.append([xy[i][0]-xy[k][0],xy[i][1]-xy[k][1]])
        dif.append([xy[k][0]-xy[i][0],xy[k][1]-xy[i][1]])
for i in range(len(dif)):
    dif[i]=str(dif[i])
c=collections.Counter(dif)
ans=list(c.values())
ans.sort(reverse=True)

if n==1:
    print(1)
else:
    print(n-ans[0])

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000)
mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y / 2) ** 2 % mod
    else:
        return power(x, y / 2) ** 2 * x % mod


def div(a, b):
    return mul(a, power(b, mod - 2))


# def gcd(a_gcd, b_gcd):
#     while b_gcd != 0:
#         a_gcd, b_gcd = b_gcd, a_gcd % b_gcd
#     return a_gcd
#
#
# def lcm(a_lcm, b_lcm):
#     return a_lcm * b // gcd(a_lcm, b_lcm)
#
#
# def max_sum(N_max_sum, a_max_sum):
#     dp = [0] * (N_max_sum + 1)
#     for i in range(N_max_sum):
#         dp[i + 1] = max(dp[i], dp[i] + a_max_sum[i])
#     return dp[N]
#
#
# def knapsack(N_knapsack, W, weight, value):
#     inf = float("inf")
#     dp = [[-inf for _ in range(W+1)] for j in range(N_knapsack + 1)]
#     for i in range(W+1):
#         dp[0][i] = 0
#
#     for i in range(N_knapsack):
#         for w in range(W+1):
#             if weight[i] <= w:
#                 dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
#             else:
#                 dp[i+1][w] = dp[i][w]
#     return dp[N_knapsack][W]
#
#
# class UnionFind:
#     def __init__(self, n):
#         self.par = [i for i in range(n+1)]
#         self.rank = [0] * (n+1)
#
#     # 検索
#     def find(self, 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 = self.find(x)
#         y = self.find(y)
#         if self.rank[x] < self.rank[y]:
#             self.par[x] = y
#         else:
#             self.par[y] = x
#             if self.rank[x] == self.rank[y]:
#                 self.rank[x] += 1
#
#     # 同じ集合に属するか判定
#     def same_check(self, x, y):
#         return self.find(x) == self.find(y)


ans = 0
N = int(input())
X = [0 for _ in range(N)]
Y = [0 for _ in range(N)]
for i in range(N):
    X[i], Y[i] = map(int, input().split())

ans = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x = X[i] - X[j]
        y = Y[i] - Y[j]
        ans_loop = 0

        for first in range(N):
            for second in range(N):
                if first == second:
                    continue
                if X[first] == X[second] - x and Y[first] == Y[second] - y:
                    ans_loop += 1
                    break

        ans = max(ans, ans_loop)

print(N-ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

from collections import defaultdict

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

max_count = 0
d = defaultdict(lambda: defaultdict(int))
for i in range(N):
    for j in range(i+1, N):
        d[X[i][0] - X[j][0]][X[i][1] - X[j][1]] += 1
        max_count = max(max_count, d[X[i][0] - X[j][0]][X[i][1] - X[j][1]])
        d[X[j][0] - X[i][0]][X[j][1] - X[i][1]] += 1
        max_count = max(max_count, d[X[j][0] - X[i][0]][X[j][1] - X[i][1]])
        
print(N - max_count)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
# xy = sorted(xy, key=lambda x: x[0])
counter = Counter()
for i in range(N):
    for j in range(i+1, N):
        nxy = xy[i]
        pxy = xy[j]
        counter[(nxy[0]-pxy[0], nxy[1]-pxy[1])] += 1
        counter[(pxy[0]-nxy[0], pxy[1]-nxy[1])] += 1
# print(counter)
if N == 1:
    print(1)
else:
    print(N-counter.most_common(1)[0][1])

Submission status: Accepted

Solution code:
N = int(input())
p = []
for i in range(N):
    x, y = [int(c) for c in input().split()]
    p.append((x,y))

t = {}
for i, pi in enumerate(p):
    for j, pj in enumerate(p):
        if i==j : continue
        
        dx, dy = pi[0] - pj[0], pi[1] - pj[1]
        if (dx, dy) in t:
            t[(dx, dy)] += 1
        else:
            t[(dx, dy)] = 1

if N==1:
    print(1)
else:
    print(N-max([t[k] for k in t]))

Submission status: Accepted

Solution code:
import collections

N = int(input())

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

if N >= 2:
    relations = []
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            else:
                relations.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))
    
    relations = collections.Counter(relations)
    most_common = relations.most_common()[0][1]
    print(N-most_common)
else:
    print(1)

Submission status: Accepted

Solution code:
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

N = int(input())
xy = []
field = defaultdict(int)
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
    field[(x,y)] = 1
xy.sort()

pq = set()
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
        pq.add((p,q))

ans = N
for p, q in pq:
    removed = defaultdict(int)
    cost = 0
    for x, y in xy:
        if removed[(x,y)]:
            continue
        else:
            removed[(x,y)] = 1
            cost += 1
            while True:
                x += p
                y += q
                if field[(x,y)]:
                    removed[(x,y)] = 1
                else:
                    break
    if cost < ans:
        ans = cost

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
m = []
for _ in range(N):
    x, y = map(int, input().split())
    m.append((x, y))
s = set(m)

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

ans = float("inf")
for i in range(N):
    x0, y0 = m[i]
    for j in range(N):
        if i == j:
            continue
        x1, y1 = m[j]
        p = x1 - x0
        q = y1 - y0
        c = 0
        for k in range(N):
            x, y = m[k]
            if (x + p, y + q) not in s:
                c += 1
        ans = min(ans, c)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    if n == 1:
        print(1)
        return
    X, Y = get_data(n, [int, int])
    vecs = Counter()
    for i in range(n):
        for j in range(i+1, n):
            if X[i] > X[j] or (X[i] == X[j] and Y[i] > Y[j]):
                vecs[(X[i]-X[j], Y[i]-Y[j])] += 1
            else:
                vecs[(X[j]-X[i], Y[j]-Y[i])] += 1
    print(n-vecs.most_common()[0][1])
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

d = {(-1, -1): 0}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        x3, y3 = x2-x1, y2-y1
        if x3 < 0 or (x3 == 0 and y3 < 0):
            x3, y3 = -1*x3, -1*y3
        pos = (x3, y3)
        if pos not in d:
            d[pos] = 0
        d[pos] += 1

# print(d.values(), d, max(d.values()))
print(N - max(d.values())//2)

Submission status: Accepted

Solution code:
n=int(input())
s=[]
d=[]
i=0
while i!=n:
    s=list(map(int,input().split()))
    d.append(s)
    i+=1
#print(d)
i=0
f=[]
s=[]
j=0
while i!=n:
    while j!=n:
        if i!=j:
            f.append(d[i][0]-d[j][0])
            f.append(d[i][1] - d[j][1])
            s.append(f)
            f=[]

        j += 1
    i+=1
    j=0


#print(s)
i=0
f=[]
while i!=len(s):
    f.append(s.count(s[i]))
    i+=1
#print(f)
try:
    print(int(n-max(f)))
except:
    print(1)

Submission status: Accepted

Solution code:
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
        #print(xy[i][0] - xy[j][0], xy[i][1] - xy[j][1])
    #print()
d = sorted(d.items(), key = lambda x:-x[1])
print(N - d[0][1])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

    #print(s)

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

Submission status: Accepted

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

dalta_data=[]
for i in range(0,N-1): #iは比較親
  Ai=data[i]
  for j in range(i+1,N): #jは比較子
    Aj=data[j]
    x=Ai[0]-Aj[0]
    y=Ai[1]-Aj[1]
    dalta_data.append([x,y])
    
#print(dalta_data)
    
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
N = int(input())

pairs = [list(map(int, input().split(" "))) for _ in range(N)]
#pairs = sorted(pairs, key=lambda x: x[0])

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

        #x3 = x2 + dx
        #y3 = y2 + dy

        #while [x3, y3] in pairs:
        #    count += 1
        #    x3 = x3 + dx
        #    y3 = y3 + dy

        counts[i][j] = count

#import numpy as np
#print(np.asarray(counts))


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

out = N - max_count
print(out)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-





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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)
#print(cost_dic)
zero_cost_num = max(cost_dic.values())
#print(zero_cost_num)
ans = n - zero_cost_num

print(ans)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
        
        # cnt = 0
        # flag = [False] * n
        # for p in range(n):
        #     if flag[p]:
        #         continue
        #     cnt += 1
        #     flag[p] = True
        #     for q in range(p + 1, n):
        #         if flag[q]:
        #             continue
        #         sb = []
        #         for a,b in zip(l[p], l[q]):
        #             sb.append(a - b)
                
        #         if sa[0] == 0:
        #             if sb[0] == 0 and sb[1] % sa[1] == 0:
        #                 flag[q] = True
        #         elif sa[1] == 0:
        #             if sb[1] == 0 and sb[0] % sa[0] == 0:
        #                 flag[q] = True
        #         else:
        #             if sb[0] % sa[0] == 0 and sb[1] % sa[1] == 0:
        #                 if sb[0] // sa[0] == sb[1] // sa[1]:
        #                     flag[q] = True
        res = min(res, cnt)
print(res)