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: Runtime Error

Solution code:
import collections
N = int(input())

cost = 0
diff_list = []
x_y_list = []

if N == 1:
    print(1)

for n in range(N):
    x, y = map(int, input().split())
    x_y_list.append((x, y))
    cost += 1

for n in range(N):
    x, y = x_y_list.pop()
    for tmp_x, tmp_y in x_y_list:
        diff_list.append((x - tmp_x, y - tmp_y))

counter = collections.Counter(diff_list)
print(cost - max(counter.values()))

Submission status: Runtime Error

Solution code:

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

##計算量に余裕があるので全探索します
for i in range(N):
    for j in range (i+1, N):
        a = [li[j][0]-li[i][0],li[j][1]-li[i][1]]
        cross.append(a) 

lencross = len(cross)

res = 0
ans = []

for i in range (lencross):
    res = 0
    for j in range (lencross):
        if cross[i] == cross[j]:
            res += 1
    ans.append(res)
maxa = max(ans)
print(N - maxa)

Submission status: Runtime Error

Solution code:
n=int(input())
xy=sorted([list(map(int,input().split())) for _ in range(n)])
#print(xy)
count=1
p=xy[-1][0]-xy[-2][0]
q=xy[-1][1]-xy[-2][1]
for i in range(n-1):
    x=xy[i][0]
    y=xy[i][1]
    if(x+p==xy[i+1][0] and y+q==xy[i+1][1]):
        x=x+p
        y=y+q
    else:
        x=xy[i+1][0]
        y=xy[i+1][1]
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy=sorted(xy)
xy_diff=[]

for i in range(0,n-1):
    xy_diff.append(xy[i][0]-xy[i+1][0])

c=Counter(xy_diff)
mode = c.most_common(1)
saihin=mode[0][0]

xy1_diff=[]

for i in range(0,n-1):
    if xy[i][0]-xy[i+1][0]==saihin:
        xy1_diff.append(xy[i][1]-xy[i+1][1])

d=Counter(xy1_diff)
mode = d.most_common(1)
kaisu=mode[0][1]


print(n-kaisu)

Submission status: Runtime Error

Solution code:
import numpy as np
import collections

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

    l1 = []
    l2 = []
    for i in range(n):
        for j in range(i, n):
            if i == j: continue
            dis1 = ball[i] - ball[j]
            dis2 = ball[j] - ball[i]
            l1.append(list(dis1))
            l2.append(list(dis2))
    # print(l1, l2)
    # c1 = collections.Counter(l1)
    # c2 = collections.Counter(l2)

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

    print(n-max(m1,m2))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
pair_list = []
diff_list = {}
for _ in range(N):
  new_pair = np.array(list(map(int, input().split())))
  for pair in  pair_list:
    diff = tuple(pair - new_pair)
    if diff in diff_list:
      diff_list[diff] += 1
    else:
      diff_list[diff] = 1
  pair_list.append(new_pair)
print(N - max(diff_list.values()))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:

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

##計算量に余裕があるので全探索します
for i in range(N):
    for j in range (i+1, N):
        a = [li[j][0]-li[i][0],li[j][1]-li[i][1]]
        cross.append(a) 

lencross = len(cross)

res = 0
ans = []

for i in range (lencross):
    res = 0
    for j in range (lencross):
        if cross[i] == cross[j]:
            res += 1
    ans.append(res)
maxa = max(ans)
print(cross)  
print(N - maxa)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import statistics
import copy
n=int(input())
if n==1:
    print(1)
else:
    x=[0]*n
    xx=[0]*(n-1)
    yy=[0]*(n-1)
    for i in range(n):
        x[i]=list(map(int,input().split()))
    x.sort(key=lambda x:x[1])
    x.sort(key=lambda x:x[0])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=statistics.mode(xx)
    Y=statistics.mode(yy)
    if X==0 and Y==0:
        XX=copy.copy(xx)
        XX.remove(0)
        X=statistics.mode(xx)
        YY=copy.copy(yy)
        YY.remove(0)
        Y=statistics.mode(yy)
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        cntx0=n-1-xx.count(0)+1
        cnty0=n-1-yy.count(0)+1
        ansxmin(max(cntx0,cnty),max(cntx,cnty0))
    else:
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        ansx=max(cntx,cnty)
    x.sort(key=lambda x:x[0])
    x.sort(key=lambda x:x[1])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=statistics.mode(xx)
    Y=statistics.mode(yy)
    if X==0 and Y==0:
        XX=copy.copy(xx)
        XX.remove(0)
        X=statistics.mode(xx)
        YY=copy.copy(yy)
        YY.remove(0)
        Y=statistics.mode(yy)
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        cntx0=n-1-xx.count(0)+1
        cnty0=n-1-yy.count(0)+1
        ansy=min(max(cntx0,cnty),max(cntx,cnty0))
    else:
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        ansy=max(cntx,cnty)
    print(min(ansx,ansy))

Submission status: Runtime Error

Solution code:
n = int(input())
xy = sorted([list(map(int, input().split())) for _ in range(n)])
dis = [0] * (n-1)
a,b = xy[0]
for idx,(x,y) in enumerate(xy[1:]):
  dis[idx] = (x-a,y-b)
  a,b = x,y

print(n - max([dis.count(tuple(i)) for i in set(dis)]))

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())
dp=[0]*(n+1)
old=[[x[1]-x[0],y[1]-y[0]],[x[0]-x[1],y[0]-y[1]]]

dp[0]=0
dp[1]=1
dp[2]=1
for j in range(3,n+1):
  new=[]
  for ii in range(j-1):
    new.append([x[j-1]-x[ii],y[j-1]-y[ii]])
    new.append([x[ii]-x[j-1],y[ii]-y[j-1]])
  for jj in range(len(new)):
    if new[jj] in old:
      dp[j]=dp[j-1]
      break
  else:
    dp[j]=dp[j-1]+1
  old+=new
print(dp[n])

Submission status: Runtime Error

Solution code:
N = int(input())

List = list(list(map(int, input().split())) for i in range(N))
# List = [[map(int, input().split())] for i in range(N)]
Data = []
# print(List)
List.sort(key=lambda x:(x[0],x[1]))



for i in range(N):
    for j in range(i+1,N):
        Data.append([List[i][0] - List[j][0], List[i][1] - List[j][1]])

# print(Data)

Duplicate = []
for k in range(len(Data)):
    Duplicate.append(Data.count(Data[k]))
    # print(Data[k])

# print(Duplicate)

ans = N - max(Duplicate)
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

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

XY.sort()

d={}

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

Submission status: Runtime Error

Solution code:

N = int(input())

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

t = 10**9
vectors = []

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

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

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

frequencies_dic = {}
M = len(vectors)
for i in range(M):
    x, y = vectors[i]
    if (x, y) not in frequencies_dic:
        frequencies_dic[(x,y)] = 1
    else:
        frequencies_dic[(x,y)] += 1

zeros = max(list(frequencies_dic.values()))
ans = N - zeros
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import Fraction
N = int(input())
l = []

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

for i in range(N):
    temp = set([])
    for j in range(i + 1, N):
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        if dx == 0:
            frac = "x=0"
        elif dy == 0:
            frac = "y=0"
        else:
            frac = Fraction(dy, dx)
            frac = str(frac)

        temp.add(frac)
    
    for frac in temp:
        if frac not in d:
            d[frac] = 1
        else:
            d[frac] += 1

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

xy.sort()
xy = xy[::-1]

import itertools

# itertools.permutations(xy, 2)

aaa = []
for i in list(itertools.combinations(xy, 2)):
    a, b, c, d = sum(i, [])
    aaa.append([str(a-c)+str(b-d)])
    # print(a,b,c,d)
# print(aaa)
aaa = sum(aaa, [])
import collections
bbb = collections.Counter(aaa)
# print(bbb.most_common())
print(n-bbb.most_common()[0][1])

Submission status: Runtime Error

Solution code:
import logging
import unittest
from collections import (
    Counter,
)

debug = logging.getLogger(__name__).debug


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


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

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

    print(len(xy) - count)


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Submission status: Runtime Error

Solution code:
import math
import fractions
import copy
import numpy as np
#以下てんぷら
def j(q):
    if q==1: print("POSSIBLE")
    elif q == 0:print("IMPOSSIBLE")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n = ip()                                     #入力整数1つ
#n,m= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
a =[]
for i in range(n):
    a.append(iprow())
a.sort()
diffa = []
diffb = []
for i in range(1,n):
    diffa.append([a[i][0]-a[i-1][0],a[i][1]-a[i-1][1]])
    diffb.append([a[i][1]-a[i-1][1],a[i][0]-a[i-1][0]])
diffa.sort()
diffb.sort()
datanumx = []
datanumy = []
datavaluex = []
datavaluey = []
for i in range(n-1):
    if diffa[i][0] == 0:
        diffa[i][0] = pow(10,10)+i+1
    if diffa[i][1] == 0:
        diffa[i][1] = pow(10,10)+i+1
for i in range(n-1):
    if diffa[i][0] not in datanumx:
        datanumx.append(diffa[i][0])
        datavaluex.append(1)
    else:
        p = datanumx.index(diffa[i][0])
        datavaluex[p]+=1

    if diffa[i][1] not in datanumy:
        datanumy.append(diffa[i][1])
        datavaluey.append(1)
    else:
        p = datanumy.index(diffa[i][1])
        datavaluey[p] += 1
usablex =sum(datavaluex)-max(datavaluex)
usabley =sum(datavaluey)-max(datavaluey)
ansa = min(usablex,usabley)
if min(datanumx) >= pow(10,10):
    ansa = n-1
if min(datanumy) >= pow(10,10):
    ansa = n-1

datanumx = []
datanumy = []
datavaluex = []
datavaluey = []
for i in range(n-1):
    if diffb[i][0] == 0:
        diffb[i][0] = pow(10,10)+i+1
    if diffb[i][1] == 0:
        diffb[i][1] = pow(10,10)+i+1
for i in range(n-1):
    if diffb[i][0] not in datanumx:
        datanumx.append(diffb[i][0])
        datavaluex.append(1)
    else:
        p = datanumx.index(diffb[i][0])
        datavaluex[p]+=1

    if diffb[i][1] not in datanumy:
        datanumy.append(diffb[i][1])
        datavaluey.append(1)
    else:
        p = datanumy.index(diffb[i][1])
        datavaluey[p] += 1
usablex =sum(datavaluex)-max(datavaluex)
usabley =sum(datavaluey)-max(datavaluey)
ansb = min(usablex,usabley)
if min(datanumx) >= pow(10,10):
    ansb = n-1
if min(datanumy) >= pow(10,10):
    ansb = n-1
print(min(ansa+1,ansb+1))

Submission status: Runtime Error

Solution code:
n = int(input())
x_list = [0]*n
y_list = [0]*n
cnt_list = [0]*n
for i in range(n):
    x_list[i], y_list[i] = map(int,input().split())

p_list = [0]*((n*(n-1))//2)
q_list = [0]*((n*(n-1))//2)

cnt = 1
for i in range(n):
    for j in range(n):
        if i == j:
            break
        p = x_list[i]-x_list[j]
        q = y_list[i]-y_list[j]
        for k in range(n-1):
            
            if p == 0 and y_list[k]%q==y_list[k+1]%q:
                cnt +=1
            elif q == 0 and x_list[k]%p == x_list[k+1]%p:
                cnt +=1
            elif x_list[k]%p == x_list[k+1]%p and y_list[k]%q==y_list[k+1]%q:
                cnt +=1
                
        cnt_list[i] = cnt
        cnt = 1

print(n-max(cnt_list)+1)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
alllist = []
minaslist = []
for i in range(N):
    a,b = map(int,input().split())
    alllist.append([a,b])

alllist.sort()

for i in range(N-1):
    minaslist.append((alllist[i+1][0]-alllist[i][0])**3 - (alllist[i+1][1]-alllist[i][1])**4)



countdict = collections.Counter(minaslist)
lista = list(countdict.most_common())
mostnum = lista[0][1]

print(len(minaslist) - mostnum + 1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

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

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

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

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

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

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

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

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

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

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

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

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

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

"""



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

    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list()
for _ in range(n):
    a.append(list(map(int, input().split())))
diff = list()
for i in range(len(a) - 1):
    for j in range(i+1, len(a)):
        x = a[j][0]-a[i][0]
        y = a[j][1]-a[i][1]
        if x<0 and y<0:
            z = (-x,-y)
        elif x<0 and y>0:
            z = (-x,-y)
        else:
            z = (x,y)
        diff.append(z)
t_diff = Counter(diff).most_common(1)[0][1]
print(n-t_diff)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
x=[]
y=[]
for i in range(n):
  X,Y=map(int,input().split())
  x.append(X)
  y.append(Y)
z=[]
for j in range(n):
  for k in range(j+1,n):
    z.append((x[j]-x[k],y[j]-y[k]))
Z=Counter(z)
m=Z.most_common()[0][1]
print(n-m)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet += [(int(line[0]), int(line[1]))]

dic = {}
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    size = math.gcd(vec[0],vec[1])
    vec[0] = vec[0]//size
    vec[1] = vec[1]//size
    vec = tuple(vec)
    if vec not in dic.keys():
      dic[vec] = set([j])
    else:
      dic[vec].add(j)
m = 0
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#N, K = map(int, input().split(" "))

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

	xy.sort()
	gess = {}
	xm = 0
	ym = 0

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

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val
		p = x - xm
		q = y - ym
		if (p,q) in gess:
			gess[(p, q)] += 1
		else:
			gess[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess, key=gess.get)
	nai = gess[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(-x[0],-x[1]))
	gess2 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val
		p = x - xm
		q = y - ym
		if (p,q) in gess2:
			gess2[(p, q)] += 1
		else:
			gess2[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess2, key=gess2.get)
	nai2 = gess2[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(x[1]))
	gess3 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val
		p = x - xm
		q = y - ym
		if (p,q) in gess3:
			gess3[(p, q)] += 1
		else:
			gess3[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess3, key=gess3.get)
	nai3 = gess3[(p,q)]

	#########
	xy = sorted(SP, key=lambda x:(-x[1]))
	gess4 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val
		p = x - xm
		q = y - ym
		if (p,q) in gess4:
			gess4[(p, q)] += 1
		else:
			gess4[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess4, key=gess4.get)
	nai4 = gess4[(p,q)]

	tmp = max(nai, nai2, nai3, nai4)

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
import statistics
import copy
n=int(input())
x=[0]*n
xx=[0]*(n-1)
yy=[0]*(n-1)
for i in range(n):
    x[i]=list(map(int,input().split()))
x.sort(key=lambda x:x[1])
x.sort(key=lambda x:x[0])
for i in range(n-1):
    xx[i]=x[i+1][0]-x[i][0]
    yy[i]=x[i+1][1]-x[i][1]
X=statistics.mode(xx)
Y=statistics.mode(yy)
if X==0 and Y==0:
    XX=copy.copy(xx)
    XX.remove(0)
    X=statistics.mode(xx)
    YY=copy.copy(yy)
    YY.remove(0)
    Y=statistics.mode(yy)
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    cntx0=n-1-xx.count(0)+1
    cnty0=n-1-yy.count(0)+1
    ansxmin(max(cntx0,cnty),max(cntx,cnty0))
else:
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    ansx=max(cntx,cnty)
x.sort(key=lambda x:x[0])
x.sort(key=lambda x:x[1])
for i in range(n-1):
    xx[i]=x[i+1][0]-x[i][0]
    yy[i]=x[i+1][1]-x[i][1]
X=statistics.mode(xx)
Y=statistics.mode(yy)
if X==0 and Y==0:
    XX=copy.copy(xx)
    XX.remove(0)
    X=statistics.mode(xx)
    YY=copy.copy(yy)
    YY.remove(0)
    Y=statistics.mode(yy)
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    cntx0=n-1-xx.count(0)+1
    cnty0=n-1-yy.count(0)+1
    ansy=min(max(cntx0,cnty),max(cntx,cnty0))
else:
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    ansy=max(cntx,cnty)
print(min(ansx,ansy))

Submission status: Runtime Error

Solution code:
N = int(input())

ball_position = []
for _ in range(N):
    i, j = map(int, input().split())
    ball_position.append((i, j))

def tuple_inverse(a):
    ai, aj = a
    if ai < 0:
        return (-ai, -aj)
    return(ai, aj)

def tup2_diff(a, b):
    ai, aj = a
    bi, bj = b
    return tuple_inverse((ai - bi , aj - bj))

calculation_list = []
for i in range(len(ball_position)):
    for j in range(i + 1, len(ball_position)):
        calculation_list.append(tup2_diff(ball_position[i], ball_position[j]))
        
import collections
c = collections.Counter(calculation_list).most_common(1)

print(N - calculation_list.count(c[0][0]))

Submission status: Runtime Error

Solution code:
from itertools import combinations


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
if N == 1:
  print(1)
else if  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[i-1][0], ball[i][1] - ball[i-1][1])) for i in range(1,N)]
  c = collections.Counter(diff)
  ans = c.most_common()[0][1]
  print(N - ans)

Submission status: Runtime Error

Solution code:
N = list(map(int, input().split()))
d = {}

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key not in d:
            d[key] = 0
        d[key] += 1
    pos.append(a)
    
print(N[0]-max(d.values()))

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
x=[]
y=[]
for i in range(n):
  X,Y=map(int,input().split())
  x.append(X)
  y.append(Y)
z=[]
for j in range(n):
  for k in range(j+1,n):
    z.append((x[j]-x[k],y[j]-y[k]))
m=z.most_common()[0][1]
print(n-m)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
n = int(input())

tmp = []
for _ in range(n):
	x, y = map(int,input().split())
	tmp.append([x,y])
ball_axis = sorted(tmp)

diff = []
for i in range(1,n):
	diff.append(str(ball_axis[i][0]-ball_axis[i-1][0])+','+str(ball_axis[i][1]-ball_axis[i-1][1]))

max_diff_count = collections.Counter(diff).most_common()[0][1]
print(n-max_diff_count)

Submission status: Runtime Error

Solution code:
N = int(input())

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

pq = {}
for i in range(N-1):
    for j in range(i+1, N):
        p, q = balls[i][0] - balls[j][0], balls[i][1] - balls[j][1]
        if p < 0:
            p, q = -p, -q
        if (p, q) in pq:
            pq[(p, q)] += 1
        else:
            pq[(p, q)] = 1

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

Submission status: Runtime Error

Solution code:
N=int(input())

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

XY.sort()

d={}

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