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:
import sys

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

for line in sys.stdin:
    x, y = map(int, line.split())
    balls.append((x, y))

balls.sort()
ans = 0
for i in range(n - 1):
    x1, y1 = balls[i]
    for j in range(i + 1, n):
        x2, y2 = balls[j]
        p, q = x2 - x1, y2 - y1
        tmp = 0
        for x, y in balls:
            if (x - p, y - q) in balls:
                tmp += 1
        ans = max(ans, tmp)
print(n - ans)

Submission status: Accepted

Solution code:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
mii=lambda:map(int,input().split())

n=int(input())

p=[list(mii()) for _ in range(n)]

d={}
for a in p:
    for b in p:
        if a==b: continue
        c=(b[0]-a[0],b[1]-a[1])
        if c in d:
            d[c]+=1
        else:
            d[c]=1

best=0
for i,j in d.items():
    best=max(best,j)

print(n-best)

Submission status: Runtime Error

Solution code:
import sys, math, re
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    x, y = i2(N)
    d = {}

    for i in range(N):
        for j in range(N):
            if i == j:
                continue

            pair = (x[i]-x[j], y[i]-y[j])
            if not pair in d:
                d[pair] = 0
            
            d[pair] += 1

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])
l=sorted(l)
s=set()
for j in range(n-1):
    for k in range(j,n):
        s.add((l[k][0]-l[j][0],l[k][1]-l[j][1]))
s_l=sorted(list(s))
cnt=[0]*len(s_l)
dic={}
for i in range(len(s_l)):
    dic[s_l[i]]=i
for j in range(n-1):
    for k in range(j+1,n):
        cnt[dic[(l[k][0]-l[j][0],l[k][1]-l[j][1])]]+=1

print(n-max(cnt))

Submission status: Runtime Error

Solution code:
n = int(input())

def find(x, par):
  if par[x] < 0:
    return x
  
  par[x] = find(par[x], par)
  return par[x]

def union(x, y, par):
  if find(x, par) == find(y, par):
    return
  
  if par[par[x]] > par[par[y]]:
    x, y = y, x
  par[x] += par[par[y]]
  par[y] = x


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

  ans = n
  for i in range(n):
    for j in range(n):
      p, q = ball[i][0] - ball[j][0], ball[i][1] - ball[j][1]
      par = [-1]*n
      for s in range(n):
        for t in range(n):
          x, y = ball[s][0] - ball[t][0], ball[s][1] - ball[t][1]
          if x == p and y == q:
            union(s, t, par)
      judge = set()
      for k in range(n):
        judge.add(find(k, par))
      if ans > len(judge):
        ans = len(judge)
  print(ans)

  
main()

Submission status: Runtime Error

Solution code:
n = int(input())

difs = {}
points = []

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

    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])

        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1

    points.append((x, y))

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

Submission status: Runtime Error

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
l=[i for i in range(n)]
xy=[list(map(int,input().split()))  for _ in range(n)]
comb=itertools.permutations(l,2)
dic={}
for c in comb:
    i,j=c
    xi,yi=xy[i]
    xj,yj=xy[j]
    p=xi-xj
    q=yi-yj
    if (p,q) not in dic:
        dic[(p,q)]=1
    else:
        dic[(p,q)]+=1
res=-1
ai=-1
for i in dic.keys():
    if res<dic[i]:
        ai=i
        res=dic[i]
print(n-dic[i])

Submission status: Runtime Error

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
l=[i for i in range(n)]
xy=[list(map(int,input().split()))  for _ in range(n)]
comb=itertools.permutations(l,2)
dic={}
for c in comb:
    i,j=c
    xi,yi=xy[i]
    xj,yj=xy[j]
    p=xi-xj
    q=yi-yj
    if (p,q) not in dic:
        dic[(p,q)]=1
    else:
        dic[(p,q)]+=1
res=-1
ai=-1
for i in dic.keys():
    if res<dic[i]:
        ai=i
        res=dic[i]
print(dic[ai])

Submission status: Runtime Error

Solution code:
N=int(input())
L=list()
R=list()
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
k=dict()
for i in range(N-1):
  for j in range(i+1,N):
    a,b=L[i]
    c,d=L[j]
    R.append([a-c,b-d])
    n=str(a-c)+" "+str(b-d)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
    R.append([c-a,d-b])
    n=str(c-a)+" "+str(d-b)
    if n in k:
      k[n]+=1
    else:
      k[n]=1
op=max(k.values())
print(N-op)

Submission status: Runtime Error

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
xy=[]
for _ in range(N):
    xy.append(lint())
xy.sort()
C=counter()
for i in range(N):
    for j in range(i+1,N):
        C.add((xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]))
print(N-max(list(C.values())))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    X = [0] * N
    Y = [0] * N
    for i in range(N):
        x, y = MI()
        X[i], Y[i] = x, y

    dct = defaultdict(int)
    for i in range(N):
        for j in range(N):
            if i == j: continue
            xi, yi = X[i], Y[i]
            xj, yj = X[j], Y[j]

            dct[(xi-xj, yi-yj)] += 1
    # print(dct)
    print(N - max(dct.values()))


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
n= int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))

Submission status: Runtime Error

Solution code:
from collections import Counter
n= int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
pq = []
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0:
      p = -p
      q = -q
    pq.append((p,q))
c = Counter(pq)
print(n-c.most_common()[0][1])

Submission status: Runtime Error

Solution code:
N = int(input())

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

from collections import defaultdict

cnt = defaultdict(int)
for pi in range(N):
    for pj in range(pi+1, N):
        if pi == pj:
            continue
        # x
        dx = abs(P[pi][0] - P[pj][0])

        # y
        dy = abs(P[pi][1] - P[pj][1])

        cnt[(dx, dy)] += 1

ans = N-max(cnt.values())
print(ans)

Submission status: Runtime Error

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

count=[]
for x1,y1 in xy:
    for x2,y2 in xy:
        if x1==x2 and y1==y2:
            continue
        c=str(x1-x2)+':'+str(y1-y2)
        count.append(c)

from collections import*
C=Counter(count)
print(N-max(C.values()))

Submission status: Runtime Error

Solution code:
N = int(input())
l=[]
for i in range(N):
   a,b=map(int,input().split())
   l.append((a,b))
l2=[]
for i in range(N):
   for j in range(N):
      if i!=j:
         l2.append((l[i][0]-l[j][0],l[i][1]-l[j][1]))
from collections import Counter
l2=max(Counter(l2).values())
print(N-l2)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
pq=[]
for i in range(n-1):
    pq.append(str(l[i+1][0]-l[i][0])+" "+str(l[i+1][1]-l[i][1]))
c=Counter(pq)
p=int(c.most_common()[0][0][0])
q=int(c.most_common()[0][0][2])
cnt=0
for i in range(n):
    if i==0:
        cnt+=1
    else:
        if not(l[i][0]-p==l[i-1][0] and l[i][1]-q==l[i-1][1]):
            cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
from collections import *
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
a=[]
for i in range(n):
  for j in range(i+1,n):
    a+=[(x[i]-x[j],y[i]-y[j])]
print(n-max(list(Counter(a).values())))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
balls = []
for _ in range(n):
    x, y = map(int, input().split())
    balls.append([x, y])
# print(balls)
delta = []
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        delta.append((dx, dy))

c_delta = collections.Counter(delta)
# print(c_delta)
print(n-c_delta.most_common()[0][1])

Submission status: Runtime Error

Solution code:
N = int(input())

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

cnt ={}

for i in range(N):
    xi = xy[i][0]
    yi = xy[i][1]

    for j in range(i+1,N):
        xj = xy[j][0]
        yj = xy[j][1]

        x_dif =xi-xj
        y_dif = yi-yj
        if x_dif<0:
            x_dif = -x_dif
            y_dif = -y_dif

        if (x_dif,y_dif)  in cnt.keys():
            cnt[x_dif,y_dif] += 1
        else:
            cnt[x_dif, y_dif] =1

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

Submission status: Runtime Error

Solution code:
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    c = collections.Counter()

    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            xi, yi = XY[i]
            xj, yj = XY[j]
            c[(xi - xj, yi - yj)] += 1

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict

n=int(input())
c=[]
for _ in range(n): c.append(list(map(int,input().split())))
dic=defaultdict(int)
for i in range(0,n-1):
    for j in range(i+1,n):
        temp=(abs(c[i][0]-c[j][0]),abs(c[i][1]-c[j][1]))
        dic[temp]+=1
print(n-max(dic.values()))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict

(n, ), *p = [[*map(int, i.split())] for i in open(0)]
d = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i != j:
            d[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += 1
print(n - max(d.values()))

Submission status: Runtime Error

Solution code:
(n,),*xy = [list(map(int, s.split())) for s in open(0)]

from collections import Counter
from itertools import combinations
c = Counter()
for (xa,ya),(xb,yb) in combinations(xy,2):
    c[(xa-xb, ya-yb)] += 1
    c[(xb-xa, yb-ya)] += 1

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

Submission status: Runtime Error

Solution code:

from collections import defaultdict

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

X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
    for j in range(i + 1, N):
        p = X[i][0] - X[j][0]
        q = X[i][1] - X[j][1]
        ctr[(p, q)] += 1
        ctr[(-p, -q)] += 1

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

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    XY = list(list(map(int, readline().split())) for _ in range(N))
    d = defaultdict(int)
    for i in range(N-1):
        x1, y1 = XY[i]
        for j in range(i+1,N):
            x2, y2 = XY[j]
            x = x2-x1
            y = y2-y1
            d[x,y] += 1
            d[-x,-y] += 1
    print(N-max(d.values()))



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
X = [0]*n
Y = [0]*n
for i in range(n):
  X[i],Y[i] = map(int,input().split())  
  
dic = {}
for i in range(n):
  for j in range(i+1,n):
    x = X[i]-X[j]
    y = Y[i]-Y[j]
    dic[(x,y)] = dic.get((x,y),0) + 1
    
print(n-max(dic.values()))

Submission status: Runtime Error

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

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

rxy = []
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        rxy.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))
cr = collections.Counter(rxy)
print(N-max(cr.values()))

Submission status: Runtime Error

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    x, y = [0]*n, [0]*n
    for i in range(n):
        x[i], y[i] = map(int, input().split())
    from collections import defaultdict
    xy = defaultdict(int)
    for i in range(n):
        for j in range(n):
            if i == j: continue
            xy[(x[i]-x[j], y[i]-y[j])] += 1
    p, q = max(xy, key=lambda x: xy[x])
    ans = n
    for i in range(n):
        for j in range(n):
            if i == j: continue
            if x[i]-x[j] == p and y[i]-y[j] == q:
                ans -= 1
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import math 

def main():
    N = int(input())
    XY = []
    for _ in range(N):
        XY.append(list(map(int,input().split())))
    XY.sort()

    MAX = 0
    for a,b in XY:
        c = defaultdict(int)

        for x,y in XY:
            xx,yy = x-a,y-b
            g = abs(math.gcd(xx,yy))
            if g == 0:
                if xx == 0 and yy==0:
                    continue
                elif xx ==0:
                    c[tuple([0,1])] += 1
                elif yy == 0:
                    c[tuple([1,0])] += 1
                
            else:
                if xx < 0:
                    x2,y2 = -xx//g,-yy//g
                else:
                    x2,y2 = xx//g,yy//g
                c[tuple([x2,y2])] += 1

        tmp = max(c.values())
        MAX = max(tmp,MAX)

    ans = len(XY) - MAX
    print(ans)

main()

Submission status: Runtime Error

Solution code:
(n,),*a=[[*map(int,i.split())]for i in open(0)]
d={}
for i,j in a:
    for x,y in a:
        if i!=x or j!=y:
            d[(i-x,j-y)]=d.get((i-x,j-y),0)+1
print(n-max(d.values()))

Submission status: Runtime Error

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    xy = [LI() for _ in range(N)]

    interval = []
    for i in range(N):
        for j in range(N):
            if i != j:
                interval.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))

    cnt = collections.Counter(interval)
    nocost = max(cnt.values())
    ans = N - nocost
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
X = []
for _ in range(N):
  X.append(list(map(int, input().split())))
  
A = []
for i in range(N):
  for j in range(i+1,N):
    A.append((abs(X[i][0]-X[j][0]), abs(X[i][1]-X[j][1])))
    
C = Counter(A)
print(N - C.most_common()[0][1])

Submission status: Runtime Error

Solution code:
N=int(input())
l=[]
l_a=[]
for i in range(N):
   l.append(list(map(int,input().split())))
for i in range(N):
   for j in range(i+1,N):
      tmp=str(l[j][0]-l[i][0])+" "+str(l[j][1]-l[i][1])
      l_a.append(tmp)
import collections
l_a=collections.Counter(l_a).most_common()
print(N-l_a[0][1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]

cnt = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        cnt[(points[i][0] - points[j][0], points[i][1] - points[j][1])] += 1

# print(cnt)
ans = n - max(cnt.values())
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
from itertools import combinations

input = sys.stdin.readline


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

    vector = defaultdict(int)
    for a, b in combinations(range(N), 2):
        dx = x[a] - x[b]
        dy = y[a] - y[b]
        if dx == 0:
            vector[(0, abs(dy))] += 1
        elif dx > 0:
            vector[(dx, dy)] += 1
        else:
            vector[(-dx, -dy)] += 1

    ans = N - max(vector.values())
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
ball_xy = []
for _ in range(n):
    x, y = (int(x) for x in input().split())
    ball_xy.append([x, y])

distance = {}

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

cost_0 = max(distance.values())

print(n-cost_0)

Submission status: Runtime Error

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

a = {}
for i in range(n):
    for j in range(i + 1, n):
        v = x[j] - x[i], y[j] - y[i]
        if v not in a:
            a[v] = 1
        else:
            a[v] += 1
ans = n - max(a.values())
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
XY.sort(key=lambda x: x[0], reverse=True)
dXY = Counter([])
for i in range(n-1):
    for j in range(i+1,n):
        dXY += Counter([str(XY[i][0]-XY[j][0])+'_'+str(XY[i][1]-XY[j][1])])
print(n-dXY.most_common()[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
XY = [list(map(int,input().split())) for _ in range(n)]
XY.sort(key=lambda x: x[0], reverse=True)
dXY = Counter([])
for i in range(n-1):
    for j in range(1,n):
        dXY += Counter([str(XY[i][0]-XY[j][0])+'_'+str(XY[i][1]-XY[j][1])])
print(n-dXY.most_common()[0][1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

cnt = defaultdict(int)
for i, (xi, yi) in enumerate(xy):
    for xj, yj in xy[i + 1:]:
        cnt[(xi - xj, yi - yj)] += 1
ans = n - max(cnt.values())
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

cnt = defaultdict(int)
for xi,yi in xy:
    for xj, yj in xy:
        cnt[(xi - xj, yi - yj)] += 1
cnt.pop((0, 0))
ans = n - max(cnt.values())
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutations
from collections import Counter

N,*xyf = map(int, open(0).read().split())
xy = [(xyf[i*2],xyf[i*2+1]) for i in range(N)]
count = []
for a, b in permutations(xy,2):
    count.append((b[0]-a[0],b[1]-a[1]))
c = Counter(count)
print(N-max(c.values()))

Submission status: Runtime Error

Solution code:
N = int(input())
lis = []
for i in range(N):
    lis.append(tuple(map(int, input().split())))
if N == 1:
    print(1)

dic = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        val = (lis[i][0]-lis[j][0], lis[i][1]-lis[j][1])
        if val in dic:
            dic[val] += 1
        else:
            dic[val] = 1
#print(dic)
print(N-max(dic.values()))

Submission status: Runtime Error

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

dic = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        val = (lis[i][0]-lis[j][0], lis[i][1]-lis[j][1])
        if val in dic:
            dic[val] += 1
        else:
            dic[val] = 1
#print(dic)
print(N-max(dic.values()))

Submission status: Runtime Error

Solution code:
import sys
import itertools
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    xy = [tuple(in_nn()) for _ in range(N)]

    comb = itertools.combinations(range(N), 2)
    d = defaultdict(int)

    for i, j in comb:
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        xd = x2 - x1
        yd = y2 - y1
        if yd < 0:
            yd = -yd
            xd = -xd
        d[(xd, yd)] += 1

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
xy = [LIST() for _ in range(N)]

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

for s, t in combinations(xy, 2):
	st = str(t[0]-s[0]) + " " +str(t[1]-s[1])
	diff.append(st)

print(max(N - Counter(diff).most_common()[0][1], 1))

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
xy = [LIST() for _ in range(N)]

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

for s, t in combinations(xy, 2):
	st = str(t[0]-s[0]) + " " +str(t[1]-s[1])
	diff.append(st)

print(max(N - Counter(diff).most_common()[0][1], 1))

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
xy = [LIST() for _ in range(N)]

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

for s, t in combinations(xy, 2):
	st = str(t[0]-s[0]) + str(t[1]-s[1])
	diff.append(st)

print(max(N - Counter(diff).most_common()[0][1], 1))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    x = [None] * N
    y = [None] * N
    for i in range(N):
        x[i], y[i] = map(int, input().split())
    
    diff = []
    nums = []
    for i in range(N):
        for j in range(i+1,N):
            if (x[j]-x[i],y[j]-y[i]) in diff:
                nums[diff.index((x[j]-x[i],y[j]-y[i]))] += 1
            else:
                diff.append((x[j]-x[i],y[j]-y[i]))
                nums.append(1)
    # print(diff)
    # print(nums)
    print(N-max(nums))
    
    

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from itertools import combinations
N = int(input())
d = [list(map(int, input().split())) for _ in range(N)]

dd = dict()
t = 0

for n ,m in combinations(d, 2):
    if n[0] == m[0]:
        t += 1
    else:
        a = (m[1]-n[1])/(m[0]-n[0])
        if a in dd:
            dd[a] += 1
        else:
            dd.setdefault(a, 1)

M = max(t, *dd.values())
if M == 1:
    print(N-1)
else:
    for i in range(1, 51):
        if M == (i*(i+1))//2:
            M = i
            break
    print(N-M)

Submission status: Runtime Error

Solution code:
from itertools import combinations
N = int(input())
d = [list(map(int, input().split())) for _ in range(N)]

dd = dict()
t = 0

for n ,m in combinations(d, 2):
    if n[0] == m[0]:
        t += 1
    else:
        a = (m[1]-n[1])/(m[0]-n[0])
        if a in dd:
            dd[a] += 1
        else:
            dd.setdefault(a, 1)

M = max(t, *dd.values())
for i in range(1, 51):
    if M == (i*(i+1))//2:
        M = i
        break
print(N-M)