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:
from collections import Counter

N = int(raw_input())

points = [map(int, raw_input().split()) for _ in xrange(N)]

# print N, points

dist = lambda p1, p2: (p1[0]-p2[0], p1[1]-p2[1])

vecs = []
for i in xrange(N):
    for j in xrange(i+1, N):
        vecs.append(dist(points[i], points[j]))

vecs_cnt = Counter(vecs)
# print Counter(vecs)
ans = max(vecs_cnt.values())

print N-ans

Submission status: Runtime Error

Solution code:
import sys
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 int(input())
from collections import defaultdict, Counter
import bisect

sys.setrecursionlimit(10000000)

n = SI()
xy = [(0,0) for _ in range(n)]
div = defaultdict(int)
for i in range(n):
    x, y = LI()
    xy[i] = (x, y)
if n==1:
    print(1)
    return 
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            div["{}_{}".format(xy[i][0] - xy[j][0], xy[i][1]- xy[j][1])] += 1

max_ = max(div.values())
print(n - max_)

Submission status: Runtime Error

Solution code:
from sys import stdin
import collections

N = int(input())

xlist=[]
ylist=[]
for i in range(N):
  x, y = map(int, stdin.readline().rstrip().split())
  xlist.append(x)
  ylist.append(y)

tupleList=[]
for i in range(N):
  for j in range(N):
    if i < j:
      tupleList.append((xlist[i] - xlist[j], ylist[i] - ylist[j]))

c = collections.Counter(tupleList)
print(N-c[max(c)])

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())))
a.sort()
diff = list()
for i in range(1, len(a)):
    diff.append((a[i][0]-a[i-1][0], a[i][1]-a[i-1][1]))
t_diff = Counter(diff).most_common(1)[0][1]
print(n-t_diff)

Submission status: Runtime Error

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

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

x=[]
y=[]

for X,Y in XY:
    x.append(X)
    y.append(Y)
    
l1=[]
c=0
for i in range(N):
    for j in range(i+1,N):
      
        l1.append(str(x[i]-x[j])+str(y[i]-y[j]))
c = collections.Counter(l1)      
values, counts = zip(*c.most_common())    
print(N-max(counts))

Submission status: Runtime Error

Solution code:
N = int(input())

List = list(list(map(int, input().split())) for i in range(N))
Data = []
# print(List)

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

n = int(input())
l = []
l1 = []
num = 1
for i in range(n):
  x, y = map(int,input().split())
  l.append((x, y))
for i in range(len(l)-1):
  a = l[i][0] - l[i+1][0]
  b = l[i][1] - l[i+1][1]
  l1.append((a,b))
c = collections.Counter(l1)
num += (n-c.most_common()[0][1]) -1
print(num)

Submission status: Runtime Error

Solution code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
cst = 1
xy.sort(key = lambda x:x[0])
keep = xy[0]
p = xy[1][0]-xy[0][0]
q = xy[1][1]-xy[0][1]
if N != 1:
    for i in range(1,N-1):
        if not(xy[i][0] == keep[0]+p and xy[i][1] == keep[1]+q):
            cst += 1
            p = xy[i+1][0] - xy[i][0]
            q = xy[i+1][1] - xy[i][1]
            keep = xy[i+1]
else:
    print(1)

print(cst)

Submission status: Runtime Error

Solution code:

def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]


    ans = num

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

            now_kyori = [data[i][0] - data[j][0], data[i][1] - data[j][1]]
            visit_list = [0 for i in range(num)]
            visit_list[i], visit_list[j] = 1, 1

            kari_num = 1

            for k in range(num):
                if visit_list[k]:
                    continue

                now_data = data[k]

                flg = 1
                for l in range(num):
                    if visit_list[l]:
                        a = data[l][0] - now_data[0]
                        b = data[l][1] - now_data[1]

                        if now_kyori[0] == 0 and now_kyori[1] == 0:
                            if a == now_kyori[0] and b == now_kyori[0]:
                                flg = 0
                        elif now_kyori[0] == 0:
                            if a == now_kyori[0] and b % now_kyori[1] == 0:
                                if b // now_kyori[1] == 1 or b // now_data[1] == -1:
                                    flg = 0
                        elif now_kyori[1] == 0:
                            if b == now_kyori[1] and a % now_kyori[0] == 0:
                                if a // now_kyori[0] == 1 or a // now_data[0] == -1:
                                    flg = 0
                        else:
                            if a % now_kyori[0] == 0 and b % now_kyori[1] == 0:
                                if a // now_kyori[0] == b // now_kyori[1]:
                                    if a // now_data[0] == 1 or a // now_data[1] == -1:
                                        flg = 0
                        if flg == 0:
                            break

                if flg:
                    kari_num += 1
                visit_list[k] = 1


            ans = min(kari_num, ans)

    print(ans)






if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
index=0
hashMap={}
listL = []
sumP=0
while index < n:
    x, y = map(int, input().split())
    listL.append([x, y])
    sumP+=1
    index+=1

memo={}
def dp(listL, hashMap, bef, key, index):
    key2 = "".join(list(map(str, listL)))+"".join(list(map(str, bef)))+key+str(index)
    if key != "":
        del listL[index]
        if key in hashMap:
            hashMap[key]+=1
        else:
            hashMap[key]=1
    if len(listL) == 1:
        if key2 in memo:
            return memo[key2]
        else:
            key = str(listL[0][0]-bef[0])+" "+str(listL[0][1]-bef[1])
            if key in hashMap:
                hashMap[key]+=1
            else:
                hashMap[key] = 1
            maxV=0
            for keys in hashMap:
                if hashMap[keys] > maxV:
                    maxV = hashMap[keys]
            memo[key2] = maxV
            return memo[key2]
    else:
        index=0
        vL = []
        while index < len(listL):
            if bef == []:
                key = ""
            else:
                key = str(listL[index][0]-bef[0])+" "+str(listL[index][1]-bef[1])
            vL.append(dp(listL, hashMap, listL[index], key, index))
            index+=1
        memo[key2] = max(vL)
        return memo[key2]

print(sumP-dp(listL, hashMap, [], "", 0))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
s = sys.stdin.readlines()
N = int(s[0])
pos_list = []
dis_dict = {}
for e in s[1:]:
    x, y = map(int, e.split())
    pos_list.append((x, y))

for i in range(N):
    for j in range(i + 1, N):
        x_dis = pos_list[i][0] - pos_list[j][0]
        y_dis = pos_list[i][1] - pos_list[j][1]
        if x_dis == 0 and y_dis == 0:
            continue
        elif x_dis < 0:
            x_dis *= -1
            y_dis *= -1
        cand = "{}_{}".format(x_dis, y_dis)
        if cand in dis_dict:
            dis_dict[cand] += 1
        else:
            dis_dict[cand] = 1

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

Submission status: Runtime Error

Solution code:
N = int(input())

X_Y = [0] * N

for i in range(N):
    X_Y[i] = tuple(map(int, input().split()))
    
combo = list(combinations(X_Y, 2))
diff = [0] * (len(combo))

for i, item in enumerate(combo):
    x_dif = item[0][0] - item[1][0]
    y_dif = item[0][1] - item[1][1]
    diff[i] = [x_dif, y_dif]

count_list = [0] * len(diff)
for k, d in enumerate(diff):
    p = d[0]
    q = d[1]
    count = 0
    for i in range(0, len(X_Y) - 1):
        if (X_Y[i][0] == X_Y[i + 1][0] + p) and X_Y[i][1] == X_Y[i + 1][1] + q:
            count += 0
        else:
            count += 1
    count_list[k] = count
print(min(count_list) + 1)

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
diff = []
data = sorted(data)
for i in range(1,N):
    diff.append((data[i][0]-data[i-1][0],data[i][1]-data[i-1][1]))
d=Counter(diff)
ans = N - max(d.values())
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort()
deff_xy = []
memo = {}
for i in range(N-1):
    x = str(xy[i+1][0]-xy[i][0])
    y = str(xy[i+1][1]-xy[i][1])
    deff_xy = ('').join([x, y])
    if deff_xy in memo:
        memo[deff_xy] += 1
    else:
        memo[deff_xy] = 1
print(max(memo.values()))

Submission status: Runtime Error

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

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

print(N - max(count_list))

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_sort = sorted(L, key=lambda x:(x[0]+x[1]))
L_dict = {}
for i in range(n-1):
    tmp0 = L_sort[i+1][0] - L_sort[i][0]
    tmp1 = L_sort[i+1][1] - L_sort[i][1]
    if (tmp0, tmp1) in L_dict:
        L_dict[(tmp0, tmp1)] += 1
    else:
        L_dict[(tmp0, tmp1)] = 1
ans = n - max(L_dict.values())
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#B問題
N = int(input())
XY = [list(map(int,input().split())) for i in range(N)]
edges = []
for i in range(N):
    x1,y1 = XY[i][0],XY[i][1]
    for j in range(N-i-1):
        J = i+j+1
        x2,y2 = XY[J][0],XY[J][1]
        dx = x2-x1
        dy = y2-y1
        if dx < 0:
            dx = -dx
            dy = -dy
        edges.append([dx,dy])
        
listcount = []
count = []
for edge in edges:
    if edge == [0,0]:
        pass
    elif edge in listcount:
        count[listcount.index(edge)]+=1
    else:
        listcount.append(edge)
        count.append(1)
        
most = max(count)
print(N-most)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

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

    pos = []
    for _ in range(N):
        pos.append(list(map(int, input().split())))
    cost = N  # 最大でN
    sub_vals = {}
    for i in range(len(pos)):
        for j in range(len(pos)):
            if i > j:
                tmp = [pos[i][0] - pos[j][0], pos[i][1] - pos[j][1]]
                key = str(tmp[0]) + str(tmp[1])
                if key not in sub_vals:
                    sub_vals[key] = 0
                else:
                    sub_vals[key] += 1

    max_val = max(sub_vals.values())
    # print(sub_vals)
    print(N - max_val - 1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input()) 
X = [[int(i) for i in input().split()] for i in range(n)] 

from collections import Counter
def cal_diff(x1, x2):
    return (x1[0] - x2[0], x1[1] - x2[1])

hoge = [cal_diff(x1, x2) for x1 in X for x2 in X if x1 != x2]
minus = Counter(hoge).most_common(1)[0][1]
ans = n - minus
print(ans)

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

	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[0],-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(xy, key=lambda x:(-x[0],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 gess3:
			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:
#!/usr/bin/python3

from itertools import combinations
from collections import Counter

n = int(input())
x = []
y = []

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

cnt = Counter()

for i, j in combinations(range(n), 2):
  dist = (x[i] - x[j], y[i]- y[j])
  cnt[dist] += 1

dist, c = cnt.most_common(1)[0]
print(n - c)

Submission status: Runtime Error

Solution code:
from pprint import pprint
from collections import defaultdict
from operator import sub

def main():
    N = int(input())
    balls = [tuple(map(int,input().split())) for _ in range(N)]
    d = defaultdict(int)
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            d[tuple(map(sub, balls[i], balls[j]))] += 1
    print(N-max(d.values()))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
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 int(input())
from collections import defaultdict, Counter
import bisect

sys.setrecursionlimit(10000000)

n = SI()
xy = [(0,0) for _ in range(n)]
div = defaultdict(int)
for i in range(n):
    x, y = LI()
    xy[i] = (x, y)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            div["{}_{}".format(xy[i][0] - xy[j][0], xy[i][1]- xy[j][1])] += 1

max_ = max(div.values())
print(n - max_)

Submission status: Runtime Error

Solution code:
#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

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

    xy.sort(key=lambda p: (p[0], p[1]))
    # print(xy)

    cand = defaultdict(lambda:0)

    for i in range(N-1):
        for j in range(i+1, N):
            p = xy[j][0] - xy[i][0]
            q = xy[j][1] - xy[i][1]
            key = '{},{}'.format(p, q)
            cand[key] += 1
    counter = Counter(cand)
    pq_count = counter.most_common()[0][1]
    # print(counter.most_common()[0])
    print(N - pq_count)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools
import collections

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

for i in range(N):
    tmp_list = list(map(int, input().split() ))
    coord_list.append(tmp_list)

relative_coord_list = []
for coord_comb in list(itertools.combinations(coord_list,2)):
    relative_coord = [abs(coord_comb[0][0] - coord_comb[1][0]), abs(coord_comb[1][0] - coord_comb[1][1])]
    relative_coord_list.append(relative_coord)

coord_collections = collections.Counter(coord_list)

target_tupple = coord_collections.most_common()[0]
result = N - target_tupple[1]

print(str(result))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
"""
map(int,input().split())

X = input().split()
x = []
for i in range(0,len(X)):
    x.append(X[i])

"""
def search(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

N = int(input())

ball = []

for n in range(N):
    x,y = map(int,input().split(" "))
    ball.append((x,y))

#最適p,q計算
pqList = []
pqCount = []
for i in range(0,N):
    for j in range(0,N):
        if i != j:
           i_x = ball[i][0]
           i_y = ball[i][1]
           j_x = ball[j][0]
           j_y = ball[j][1]
           s = search(pqList,(i_x-j_x,i_y-j_y))
           if s != -1 :
               pqCount[s] += 1
           else:
               pqList.append((i_x-j_x,i_y-j_y))
               pqCount.append(1)

print(int(N - (max(pqCount))))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

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


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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

distant = [0]*(N*(N-1)//2)
ct = 0
for i in range(N-1):
    for j in range(i+1, N):
        x1, y1 = dot[i]
        x2, y2 = dot[j]
        distant[ct] = abs(x2-x1)+abs(y2-y1)
        ct += 1

ans = Counter(distant).most_common()[0][1] // 2

print(ans if ans != 0 else 1)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]

diff = []

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            if xy[i][0] > xy[j][0]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] >= xy[j][1]:
                diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
            elif xy[i][0] == xy[j][0] and xy[i][1] < xy[j][1]:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
            else:
                diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
c = collections.Counter(diff)
ans = N - sorted(list(c.values()))[-1] // 2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
cst = 1
keep = xy[0]
xy.sort(key = lambda x:x[0])
p = xy[1][0]-xy[0][0]
q = xy[1][1]-xy[0][1]
for i in range(1,N-1):
    if not(xy[i][0] == keep[0]+p and xy[i][1] == keep[1]+q):
        cst += 1
        p = xy[i+1][0] - xy[i][0]
        q = xy[i+1][1] - xy[i][1]
        keep = xy[i+1]

print(cst)

Submission status: Runtime Error

Solution code:
n = int(input())

li = []

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

li.sort()

diff_dic = {}

dup = []

x1, y1 = li[0]
for s in range(1,n):
    for i in range(s,n):
        xi, yi = li[i]

        if xi != x1:
            diff = (yi - y1)/(xi - x1)
        else:
            diff = 10e10

        if diff in diff_dic.keys():
            diff_dic[diff] += 1
        else:
            diff_dic[diff] = 1

        dup.append(max(diff_dic.values()))

print(n-max(dup))

Submission status: Runtime Error

Solution code:
N = int(input())
L = sorted([list(map(int,input().split())) for i in range(N)])

D = {}

for i in range(N-1) :
    ax,ay = L[i]
    for j in range(i+1,N) :
        bx,by = L[j]
        
        p = bx-ax
        q = by-ay
        tag = str(p)+str(q)
        if tag not in D :
            D[tag] = 1
        else :
            D[tag] += 1

ans = N-max(D.values())

print(ans)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
A = []
B = []
YHASHNUM = 1000000000
for i in range(N):
    A.append(list(map(int, input().split())))
#print(N, A)
for i in A:
    #print(i[0], i[1])
    for j in A:
        if i == j:
            continue
        B.append(i[0] - j[0] + (i[1] - j[1]) * YHASHNUM)
#print(B)
C = collections.Counter(B)
print(N - C.most_common()[0][1])

Submission status: Runtime Error

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

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

PQ = {}
for i in range(1, len(XY)):
    pq = XY[i][0] - XY[i-1][0], XY[i][1] - XY[i-1][1]
    if pq in PQ.keys():
        PQ[pq] += 1
    else:
        PQ[pq] = 1
pq = max(PQ, key=lambda x: PQ[x])
print(N - PQ[pq])

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:
    XX=copy.copy(xx)
    XX.remove(0)
    X=statistics.mode(xx)
if Y==0:
    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
print(max(cntx,cnty))

Submission status: Runtime Error

Solution code:
import collections

n = input()
N = int(n)

XY = []
for i in range(N):
    x, y = input().split()
    X = int(x)
    Y = int(y)
    XY.append((X, Y))

diff = []
for xy in XY:
    for xy2 in XY:
        dx = xy[0] - xy2[0]
        dy = xy[1] - xy2[1]
        # d = dx * 10 + dy
        d = (dx, dy)
        if d[0] == 0 and d[1] == 0:
            continue
        diff.append(d)    
clist = collections.Counter(diff)
result = N - clist.most_common()[0][1]
print(result)

Submission status: Runtime Error

Solution code:
N = int(input())

prev_a, prev_b = map(int, input().split())
diffs = {}
for _ in range(N - 1):
  a, b = map(int, input().split())
  key = "{} {}".format(prev_a - a, prev_b - b)
  if key not in diffs:
    diffs[key] = 1
  else:
    diffs[key] += 1

if (len(diffs.values()) == 1):
  print(1)
else:
  print(N - 1 - max(diffs.values()))

Submission status: Runtime Error

Solution code:
#-*- coding: utf-8
#  -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(n, S):
    dp = defaultdict(int)
    pre_x = None
    pre_y = None
    for i, (x, y) in enumerate(S):
        #print(x, y, pre_x, pre_y)
        if i == 0:
            pre_x, pre_y = x, y
        else:
            dp[(x - pre_x, y - pre_y)] +=1
            pre_x, pre_y = x, y
    #print(dp)
    return n - max(dp.values())


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    #print(parsed_lines)
    n = int(parsed_lines[0][0])
    #W = [int(x) for x in parsed_lines[1]]
    S = []
    for i in range(1, n+1):
        x = int(parsed_lines[i][0])
        y = int(parsed_lines[i][1])
        S.append((x, y))
    # k = int(parsed_lines[0][1])
    # S = parsed_lines[1][0]
    # return n, k, S
    return n, S


if not do_submit:
    n, S = input_parse("""
    2
    1 1
    2 2
    """)
    print(sol(n, S))

    n, S = input_parse("""
    3
    1 4
    4 6
    7 8
    """)
    print(sol(n, S))

    n, S = input_parse("""
    4
    1 1
    1 2
    2 1
    2 2
    """)
    print(sol(n, S))


else:
    n = int(input())
    S = []
    for i in range(n):
        x ,y = list(map(int, input().split()))
        S.append((x, y))
    # print(sol(n, k, S))
    #S = input().strip()
    # S = input().strip()
    print(sol(n, S))

Submission status: Runtime Error

Solution code:
import itertools
from collections import Counter
from collections import defaultdict

d = defaultdict(lambda:-1)
N = int(input())
X = [0]*N
Y = [0]*N
for i in range(N):
    X[i],Y[i] = map(int,input().split())
    d[(X[i],Y[i])] = i

o = []
for i,j in itertools.product(range(N),range(N)):
    if i == j:
        continue
    x = X[i] - X[j]
    y = Y[i] - Y[j]
    o.append((x,y))

p,q = Counter(o).most_common()[0][0]
o = []
for i in range(N):
    a = i
    while True:
        b = d[(X[a]+p,Y[a]+q)]
        if b == -1:
            o.append(a)
            break
        a = b

print(len(set(o)))

Submission status: Runtime Error

Solution code:
n=int(input())
xy=[]
for i in range(n):
    a=[int(j) for j in input().split()]
    xy.append(a)

l=[]
ans=0
import itertools
for a,b in itertools.combinations(xy,2):
    p=abs(a[0]-b[0])
    q=abs(a[1]-b[1])
    l.append((p,q))

import collections
c=collections.Counter(l)
ans=c.most_common()

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

Submission status: Runtime Error

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
a = []
b = []
for i in range(n):
    x, y = readmi()
    a.append([x,y])
    b.append([y,x])
a.sort(reverse=True)
b.sort(reverse=True)
aa = defaultdict(int)
bb = defaultdict(int)

old1 = 0
old2 = 0
flg = True
for i in range(n - 1):
    aa[(a[i + 1][0] - a[i][0], a[i + 1][1] - a[i][1])] += 1
    bb[(b[i + 1][0] - b[i][0], b[i + 1][1] - b[i][1])] += 1

aaa = sorted(aa.items(), key=lambda x:x[1],reverse=True)
bbb = sorted(bb.items(), key=lambda x:x[1], reverse=True)
ccc = defaultdict(int)

if aaa[0][1] >= bbb[0][1]:
    ccc = aaa[0]
else:
    ccc = bbb[0]
print(n - ccc[1])