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

def solve(N, xys):
    diff = []
    diff_count = []
    idx = 0
    for i in range(N-1):
        for j in range(i+1,N):
            tmp_a = [xys[i][0] - xys[j][0], xys[i][1] - xys[j][1]]
            tmp_b = [xys[j][0] - xys[i][0], xys[j][1] - xys[i][1]]
            if tmp_a in diff:
                diff_count[diff.index(tmp_a)] += 1
            elif tmp_b in diff:
                diff_count[diff.index(tmp_b)] += 1
            else:
                diff.append(tmp_a)
                diff_count.append(1)
                idx += 1
    return N - max(diff_count)

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    xys = []
    for i in range(N):
        xys.append([int(x) for x in stdin.readline().rstrip().split()])
    print(solve(N, xys))

Submission status: Runtime Error

Solution code:
from sys import stdin

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

for i in range(N):
  for j in range(N):
    if i != j:
      tupleStr=str(xlist[i] - xlist[j])+","+str(ylist[i] - ylist[j])
      if tupleStr in dict:
        dict[tupleStr]+=1
      else:
        dict[tupleStr]=1

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

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<0:
            key=-key
    pos.append(a)
    
print(N[0]-max(d.values()))

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:
n = int(input())
L = []
for i in range(n):
    x,y = map(int, input().split())
    L.append((x,y))

if n == 1:
    print(1)

if n == 2:
    print(1)

else:
    L_sort = sorted(L)
    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

    print(L_dict)
    ans = n - max(L_dict.values())
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

xy.sort()

ans = 0
while len(xy) > 2:
  rem_list = [[] for _ in range(N)]
  rem_cnt = 0
  rem_num = 0
  for i in range(1, N):
    p, q = xy[i][0] - xy[0][0], xy[i][1] - xy[0][1]
    cnt = 0
    for j in range(1, N):
      if p == 0 and xy[j][0] == xy[0][0] or q == 0 and xy[j][1] == xy[0][1]:
        cnt += 1
        rem_list[j].append(xy[j])
      elif p != 0 and q != 0 and (xy[j][0] - xy[0][0]) % p == 0 and (xy[j][0] - xy[0][0]) * p > 0 and (xy[j][1] - xy[0][1]) % q == 0 and (xy[j][1] - xy[0][1]) * q > 0:
        cnt += 1
        rem_list[j].append(xy[j])
    if rem_cnt < cnt:
      rem_cnt = cnt
      rem_num = i
  for r in rem_list[rem_num]:
    xy.remove(r)
  del xy[0]
  ans += 1

if len(xy) > 0:
  ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
list_coord = list()
for i in range(N):
    list_coord.append([int(i) for i in input().split()])
arr_coord = np.array(list_coord)

arr_pat = np.array([])
for i in range(N):
    for j in range(N):
        if i > j:
            arr_pat = np.append(arr_pat, (arr_coord[i] - arr_coord[j]))

arr_pat = arr_pat.reshape(int(len(arr_pat)/2), 2)

arr_pat_uni, arr_pat_cnt = np.unique(arr_pat, axis=0, return_counts=True)

print(int(N-np.max(arr_pat_cnt)))

Submission status: Runtime Error

Solution code:
from collections import Counter

data = []
N = int(input())
for i in range(N):
	data.extend([list(map(int, input().split(' ')))])
print(data)
x = []

for e_set in data:
    for sub_set in data:
        x.append((e_set[0] - sub_set[0], e_set[1] - sub_set[1]))
x.remove((0, 0))
val = Counter(x)

commons = val.most_common()[0][1]
if commons > 2:
  commons - 1
ans = N - commons
print(ans)

Submission status: Runtime Error

Solution code:
import math

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


def katamuki(balla, ballb):
    xa, ya = balla
    xb, yb = ballb
    x, y = (xa - xb), (ya - yb)
    dir = math.sqrt(y ** 2 + x ** 2)
    if x == 0:
        return 1.0, dir
    if y == 0:
        return 0.0, dir
    if y / x == -1.0:
        return 1.0, dir
    return y / x, dir


a = []
for i in range(0, n - 1):
    for j in range(i + 1, n):
        a.append(katamuki(balls[i], balls[j]))

a.sort()
tmp = a[0]
cnt = 0
ans = []
a.append(10000000)
for i in range(len(a)):
    if a[i] == tmp:
        cnt += 1
    else:
        ans.append(cnt)
        tmp = a[i]
        cnt = 1

print(n - max(ans))

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], x[1]))

diff = []
for X, Y in XY:
  for X2, Y2 in XY:
    p = X2-X
    q = Y2-Y
    if (p, q) == (0, 0) or (p, q) in diff:
      continue
    diff.append((p, q))

pre = []
ans = []
for p, q in diff:
  cost = 1
  for a, b in XY:
    if not pre:
      pre = (a, b)
      continue
    if (a - p, b - q) == pre:
      pass
    else:
      cost += 1
    pre = (a, b)
  ans.append(cost)
  pre = []
print(min(ans))

Submission status: Runtime Error

Solution code:
# div2019-2B - Picking Up
import collections
import sys
input = sys.stdin.readline

n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
dif = []
for i in range(1, n):
    x = arr[i][0] - arr[i - 1][0]
    y = arr[i][1] - arr[i - 1][1]
    dif += [(x, y)]

x_min, x_max = min(dif, key=lambda i: i[0])[0], max(dif, key=lambda i: i[0])[0]
y_min, y_max = min(dif, key=lambda i: i[1])[1], max(dif, key=lambda i: i[1])[1]
ans = float("inf")
for p in range(x_min, x_max + 1):
    for q in range(y_min, y_max + 1):
        cnt = 1
        for i in range(1, n):
            if (arr[i - 1][0], arr[i - 1][1]) != (arr[i][0] - p, arr[i][1] - q):
                cnt += 1
        ans = min(ans, cnt)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

salist=[]
for i in range(1,len(balls),1):
  sax = balls[i][0]-balls[i-1][0]
  say = balls[i][1]-balls[i-1][1]
  salist.append([sax,say])
  
balls.reverse()
costs=[]
for i,sa in enumerate(reversed(salist)):
  cost=1
  for i in range(0,len(balls)-1,1):
    if balls[i+1][0]!=balls[i][0]-sa[0] and balls[i+1][1]!=balls[i][1]-sa[1]:
      cost+=1
  costs.append(cost)

print(min(costs))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
list_coord = list()
for i in range(N):
    list_coord.append([int(i) for i in input().split()])
arr_coord = np.array(list_coord)

arr_pat = np.array([])
for i in range(N):
    for j in range(N):
        if i > j:
            arr_pat = np.append(arr_pat, (arr_coord[i] - arr_coord[j]).astype('int32'))

arr_pat = arr_pat.reshape(int(len(arr_pat)/2), 2)

arr_pat_uni, arr_pat_cnt = np.unique(arr_pat, axis=0, return_counts=True)

print(int(N-np.max(arr_pat_cnt)))

Submission status: Runtime Error

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

dl = {}
for i in range(N):
  for j in range(N):
    dx = str(xylist[j][0] - xylist[i][0])
    dy = str(xylist[j][1] - xylist[i][1])
    l = dx + "|" + dy
    if dx == "0" and dy == "0":
      continue
    if l in dl:
      dl[l] = dl[l] + 1
    else:
      dl[l] = 1

cnt = N - max(dl.values())
print(cnt if cnt > 1 else "1")

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())

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

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

def valid(steps):
    for i , x in enumerate(sorted(steps)):
        if i != x:
            return i - 1

    return len(steps) - 1
#
n = getN()
za = []
for i in range(n):
    za.append(getlist())
ans = 0
from collections import defaultdict
kumi = defaultdict(int)

for i, pa in enumerate(za):
    for j, pb in enumerate(za[i:]):
        xa, ya = pa
        xb, yb = pb
        dfx = xa - xb
        dfy = ya - yb

        diff = str(dfx) + str(dfy)
        kumi[diff] += 1

del kumi["00"]
print(n - max(list(kumi.values())))

# for p1 in za:
#     for p2 in za:
#         steps = []
#         if p1 == p2:
#             continue
#         xa, ya = p1
#         xb, yb = p2
#         dfx = xb - xa
#         dfy = yb - ya
#         if not (dfx or dfy):
#             continue
#         for p3 in za:
#             xc, yc = p3
#             if dfx:
#                 if (xc - xa) % dfx == 0:
#                     step = (xc - xa) // dfx
#                     if yc - ya == dfy * step:
#                         steps.append(step)
#
#             else:
#                 if xc == xa:
#                     if (yc - ya) % dfy == 0:
#                         steps.append((yc - ya) // dfy)
#         tmp = valid(steps)
#         print(p1, p2, tmp, steps)
#         if tmp > ans:
#             ans = tmp
#             if tmp == 3:
#                 print(p1, p2)
#
# print(n-ans)

Submission status: Runtime Error

Solution code:

N = int(input())
p = []
dic = {}
sameX = {}
allNum = []

for i in range(N):

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

    p.append([x,y])

    allNum.append(i)


for i in range(N):

    for j in range(i):

        ji = [j,i]
        

        if p[j][0] - p[i][0] != 0:

            a = ( p[j][1] - p[i][1] ) / ( p[j][0] - p[i][0] )
            b = p[j][1] - ( a * p[j][1] )

            if a == -0.0:
                a = 0.0
            
            ab = [a,b]

            if ( str (ab) )  in dic:
                dic[ str (ab) ].append(ji)

            else:
                dic[ str(ab) ] = [ji]

        elif p[j][0] - p[i][0] == 0:

            if p[j][0] in sameX:
                sameX[ p[j][0] ].append(ji)
            else:
                sameX[ p[j][0] ] = [ji]
            

#print  (dic,sameX)
        

DorS = 0
maxi = 0
keys = ""
ans = 0

while len(allNum) > 0:

    DorS = 0
    maxi = 0
    keys = ""

    for i in dic:
        
        eable = {}
        
        for j in dic[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            
                

        if len(eable) > maxi:

            
            DorS = 0
            maxi = len(dic[i])
            keys = i

    for i in sameX:

        eable = {}

        for j in sameX[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            

        if len(eable) > maxi:

            DorS = 1
            maxi = len(sameX[i])
            keys = i


    if DorS == 0:

        delPs = dic[keys]
        del dic[keys]

    else:

        delPs = sameX[keys]
        del sameX[keys]


    #print (delPs)

    rmFlag = False

    for i in delPs:

        if i[0] in allNum :
            allNum.remove(i[0])
            rmFlag = True

        if i[1] in allNum :
            allNum.remove(i[1])
            rmFlag = True

    if rmFlag :
        ans += 1

    #print (allNum)

        
print (ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
list_coord = list()
for i in range(N):
  list_coord.append([int(i) for i in input().split()])
arr_coord = np.array(list_coord)

arr_pat = np.array([])
for i in range(N):
    for j in range(N):
        if i > j:
            arr_pat = np.append(arr_pat, (arr_coord[i] - arr_coord[j]).astype('int32'))

arr_pat = arr_pat.reshape(int(len(arr_pat)/2), 2)

arr_pat_uni, arr_pat_cnt = np.unique(arr_pat, axis=0, return_counts=True)

print(int(N-np.max(arr_pat_cnt)))

Submission status: Runtime Error

Solution code:
import fractions
def reducea(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)

n = int(input())
balls = []
vectors = {}
for i in range(n):
    x, y = map(int, input().split())

    for ball in balls:
        mx, my = ball
        vx = x - mx
        vy = y - my
        vx, vy = reducea(vx, vy)
        # 傾き分ループしてあれば＋、無ければ追加
        if (vx, vy) in vectors:
            for vector in vectors:
                if vector != (vx, vy):
                    vectors[vector] = vectors[vector] + 1
        else:
            vectors[(vx, vy)] = 1
    balls.append((x, y))
ans = None
for vector in vectors:
    if ans == None:
        ans = vectors[vector]
    else:
        ans = min(vectors[vector], ans)
print(ans + 1)

Submission status: Runtime Error

Solution code:
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
    try:
        mmax = max(d.values())
        mmax = N - mmax
    except:
        print(100)
    if mmax >= 0:
        print(mmax)
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

sabun = []
for i in range(N):
    for j in range(N-i-1):
        p = xy[i][0] - xy[j+i+1][0]
        q = xy[i][1] - xy[j+i+1][1]
        # print(p,q)
        sabun.append([p,q])
count = [sabun.count(i) for i in sabun]
# print(sabun)
print(N-max(count))

Submission status: Runtime Error

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

dl = {}
for i in range(N):
  for j in range(i+1, N):
    dx = str(xylist[j][0] - xylist[i][0])
    dy = str(xylist[j][1] - xylist[i][1])
    l = dx + "|" + dy
    if dx == "0" and dy == "0":
      continue
    if l in dl:
      dl[l] = dl[l] + 1
    else:
      dl[l] = 1

cnt = N - max(dl.values())
print(cnt if cnt > 1 else "1")

Submission status: Runtime Error

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

vecs = {}
for i in range(n):
  for j in range(i+1, n):
    if xy[i][0] < xy[j][0]:
      vec = (xy[j][0] - xy[i][0], xy[j][1] - xy[i][1])
    elif xy[i][0] > xy[j][0]:
      vec = (xy[i][0] - xy[j][0], xy[i][1] - xy[j][1])
    else:
      vec = (0, abs(xy[j][1] - xy[i][1]))
    
    if vec in vecs:
      vecs[vec] += 1
    else:
      vecs[vec] = 1

vec_max = max(list(vecs.values()))
print(n - vec_max)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# B - Picking Up
n = int(input())
ball = [list(map(int, input().split())) for i in range(n)]

dis  = []
for i in range(n):
    for j in range(n):
        if i != j:
            dis.append([ball[i][0] - ball[j][0], ball[i][1] - ball[j][1]])
            
cnt = []
for i in range(len(dis)):
    cnt.append(dis.count(dis[i]))
print(n - max(cnt))

Submission status: Runtime Error

Solution code:
import math

def main():
	n = int(input())
	xy = []
	for _ in range(n):
		xy +=[list(map(int,input().split()))]
	xy.sort(key=lambda x:(x[0],x[1]))
	dic = {}
	for i in range(n):
		for j in range(i+1,n):
			x,y = xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]
			if x*y == 0:
				temp = f"{x}.{y}"
			else:
				g = math.gcd(x,y)
				k = "" if x*y > 0 else "-"
				x = abs(x)//g
				y = abs(y)//g
				temp = f"{x}.{k}{y}"
			if temp in dic:
				dic[temp] = dic[temp]+1
			else:
				dic[temp] = 1
	ans = 100
	# print(dic, xy)
	for d in dic:
		p,q = map(int,d.split("."))
		nlst = xy
		tans = 0
		lenn = n
		while lenn != 0:
			tans += 1
			f = nlst[0]
			nnlst = []
			# print("print f ", f)
			for i in range(1,lenn):
				if p == 0:
					if ((nlst[i][1] - f[1]) % q != 0)or (nlst[i][0] != f[0]):
						nnlst += [nlst[i]]
					else:
						lenn -= 1
				elif q == 0:
					if ((nlst[i][0] - f[0]) % p != 0) or (nlst[i][1] != f[1]):
						nnlst += [nlst[i]]
					else:
						lenn -= 1
				else:
					# print(f"{abs(nlst[i][1] - f[1]) % q} {abs(nlst[i][0] - f[0]) % p}")
					if (((nlst[i][1] - f[1]) % q) != 0) or (((nlst[i][0] - f[0]) % p) != 0):
						nnlst +=[nlst[i]]
					else:
						if (nlst[i][1]-f[1]) == 0 or ((nlst[i][0]-f[0])==0):
							nnlst += [nlst[i]]
						else:	lenn -= 1
			lenn -= 1
			# print(nnlst)
			nlst = nnlst
		# print(f"{d},{tans}")
		ans = min(tans,ans)
	print(ans)
	return

main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

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

        ball.append(temp_list)
    
    diff_list=[]
    for j in range(n-1):
        
        temp_diff=np.array(ball[j+1])-np.array(ball[j])
        
        diff_list.append(list(temp_diff))

    count=[]
    for i in range(len(diff_list)):
        count.append(diff_list.count(diff_list[i]))

    max_index=np.argmax(count)
    
    max_pair=diff_list[max_index]
    

    loss=1
    for i in range(len(diff_list)):
        if(diff_list[i])!=max_pair:
            loss+=1
    print(loss)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin

N=int(input())
xlist=[]
ylist=[]
dict = {}
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:
      tuple = (xlist[i] - xlist[j], ylist[i] - ylist[j])
      if tuple in dict:
        dict[tuple]+=1
      else:
        dict[tuple]=1

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

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

d = []
for i, pp1 in enumerate(p):
    for j in range(i + 1, N):
        pp2 = p[j]
        d.append((pp1[0] - pp2[0], pp1[1] - pp2[1]))

c = Counter(d)

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

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)
if N-1 < max(ans):
    reduce = N-1
else:
    reduce = max(ans)

if N != 1:
    print(N - reduce)
else:
    print(1)

Submission status: Runtime Error

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


class UnionFind(object):
    def __init__(self, N):
        self._parent = list(range(N))
        self.__num_components = [1] * N

    def root(self, x):
        if self._parent[x] == x:
            return x
        else:
            # root abbreviation
            self._parent[x] = self.root(self._parent[x])
            return self._parent[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def num_connected(self, x):
        return self.__num_components[self.root(x)]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if (x == y):
            return
        rank_x = self.__num_components[x]
        rank_y = self.__num_components[y]
        if rank_x < rank_y:
            self._parent[x] = y
            self.__num_components[y] += rank_x
        else:
            self._parent[y] = x
            self.__num_components[x] += rank_y
        return


fin = sys.stdin.readline

N = int(fin())
coordinates = [[int(elem) for elem in fin().split()] + [i] for i in range(N)]

# p, qのペアを計算
pq_set = set()
all_dists = defaultdict(list)
count_dist_set = defaultdict(set)
for each_pair in combinations(coordinates, 2):
    each_p = each_pair[0][0]-each_pair[1][0]
    each_q = each_pair[0][1] - each_pair[1][1]
    if each_p < 0:
        each_p = -each_p
        each_q = -each_q
    each_pq = (each_p, each_q)
    pq_set.add(each_pq)
    all_dists[each_pq].append([each_pair[0][2], each_pair[1][2]])
    count_dist_set[each_pq] = count_dist_set[each_pq].union({each_pair[0][2], each_pair[1][2]})

# 適当にスタート，探索を行う
count_list = []
count_tree_dic = {}
for each_pq in all_dists:
    uf = UnionFind(N)
    for x, y in all_dists[each_pq]:
        uf.unite(x, y)
    num_distinct_components = 0
    for i in range(N):
        if uf.root(i) == i:
            num_distinct_components += 1
    count_tree_dic[each_pq] = num_distinct_components
    count_list.append(num_distinct_components)

print(max(min(count_list), 1))

Submission status: Runtime Error

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

from itertools import combinations
L = []
for (x1, y1), (x2, y2) in combinations(R, 2):
    L.append((x1 - x2, y1 - y2))
    L.append((-x1 + x2, -y1 + y2))

from collections import Counter
C = Counter(L)
print(N - C.most_common(1)[0][1])

Submission status: Runtime Error

Solution code:
N = int(input())
xy = [[int(x) for x in input().split()] for i in range(N)]
xy = sorted(xy)
ans = 1
if N <= 2:
  print(ans)
else:
  list_xypq = [[xy[0][0],xy[0][1],xy[1][0]-xy[0][0],xy[1][1]-xy[0][1]]]
  for i in range(2,N):
    x = int(xy[i][0])
    y = int(xy[i][1])
    for j in range(len(list_xypq)):
      x_tmp = int(list_xypq[j][0])
      y_tmp = int(list_xypq[j][1])
      p_tmp = int(list_xypq[j][2])
      q_tmp = int(list_xypq[j][3])
      if p_tmp == 10e10 and q_tmp == 10e10:
        list_xypq[j][2] = x-x_tmp
        list_xypq[j][3] = y-y_tmp
        break
      if p_tmp == 0 and q_tmp != 0:
        if x-x_tmp == 0 and (y-y_tmp)%q_tmp == 0:
          break
      elif p_tmp != 0 and q_tmp != 0:
        if (x-x_tmp)%p_tmp == 0 and y-y_tmp == 0:
          break
      elif  p_tmp == 0 and q_tmp == 0:
        if x-x_tmp == 0 and y-y_tmp == 0:
          break
      elif (x-x_tmp)%p_tmp == 0 and (y-y_tmp)%q_tmp == 0:
        break
    else:
      list_xypq.append([x,y,10e10,10e10])
      ans += 1
      continue
    break
  print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
X,Y = [],[]
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
inf = 10**10

d = {}
for i in range(N):
    for j in range(i+1,N):
        if X[i] >= X[j]:
            r,l = i,j
        else:
            r,l = j,i
        k = (X[r]-X[l],Y[r]-Y[l])
        if k in d.keys():
            d[k] += 1
        else:
            d[k] = 1

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

Submission status: Runtime Error

Solution code:
from sys import stdin

def solve(N, xys):
    diff = []
    diff_count = []
    idx = 0
    for i in range(N-1):
        for j in range(i+1,N):
            tmp_a = [xys[i][0] - xys[j][0], xys[i][1] - xys[j][1]]
            tmp_b = [xys[j][0] - xys[i][0], xys[j][1] - xys[i][1]]
            if tmp_a in diff or tmp_b in diff:
                diff_count[diff.index(tmp_a)] += 1
            else:
                diff.append(tmp_a)
                diff_count.append(1)
                idx += 1
    return N - max(diff_count)

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    xys = []
    for i in range(N):
        xys.append([int(x) for x in stdin.readline().rstrip().split()])
    print(solve(N, xys))

Submission status: Runtime Error

Solution code:
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
    try:
        mmax = max(d.values())
        mmax = N - mmax
    except:
        print(100)
    print(mmax)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import pandas as pd
import statistics as stat

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

df = pd.DataFrame(xy)
df.columns = ['x', 'y']
df['xy'] = df.sum(axis=1)
df2 = df.sort_values(by=['xy'], ascending=True)

x = df2['x'].shift(-1) - df2['x'] 
x2 = stat.mode(x)

y = df2['y'].shift(-1) - df2['y']  
y2 = stat.mode(y)

cst = 1

for i in n-1:
	if x[i] != x2 or y[i] != y2:
      cst += 1

print(cst)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
from sympy import *
p = Symbol('p')
q = Symbol('q')
costs = []
N = int(input())
x, y = [], []
# (x,y)の値を取得
for n in range(N):
    temp = list(map(int, input().split()))
    x.append(temp[0])
    y.append(temp[1])
# コスト計算
for n, perm in enumerate(itertools.permutations(zip(x,y), N)):
    sol = 0
    cost = 1
    for i in range(1, N):
        if i == 1:
            sol = solve([perm[i][0]-p-perm[i-1][0], perm[i][1]-q-perm[i-1][1]], [p,q])
            #print(sol)
        else:
            if perm[i][0] - sol[p] == perm[i-1][0] and perm[i][1] - sol[q] == perm[i-1][1]:
                cost += 0
            else:
                cost += 1
    costs.append(cost)
#print(costs)
print(np.min(costs))

Submission status: Runtime Error

Solution code:
import sys
import collections
input = sys.stdin.readline
n = int(input())
xy = []
for i in range(n):
    _a,_b = map(int,input().split())
    xy.append([_a,_b])
sxy = sorted(xy)
sxy2 = []
for i in range(1,n):
    sxy2.append(((sxy[i][0]-sxy[i-1][0])**2)+((sxy[i][1]-sxy[i-1][1])**2))
c = collections.Counter(sxy2)
ans = len(sxy2)-max(c.values())+1
print(ans) if ans != 0 else print(1)

Submission status: Runtime Error

Solution code:
# B - Picking Up

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

dis  = []
for i in range(n):
    for j in range(n):
        if i != j:
            dis.append([ball[i][0] - ball[j][0], ball[i][1] - ball[j][1]])
            
cnt = []
for i in range(n):
    cnt.append(dis.count(dis[i]))
print(n - max(cnt))

Submission status: Runtime Error

Solution code:
n = int(input())
xy = []
renso = {}

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

xy.sort()

for i in range(n):
    for j in range(i,n):
        if( i==j ):
            continue
        if renso.get((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))==None:
            renso[(xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])]=1
        else:
            renso[(xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])]=renso[(xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])]+1

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

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
l = []
l1 = []
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)
values, counts = zip(*c.most_common())
for i, j in zip(values, counts):
  if i[0] != 0 or i[1] != 0:
    num = n-j
    break
  else:
    num = n
print(num)

Submission status: Runtime Error

Solution code:
import logging
import numpy as np

logging.disable(logging.CRITICAL)
logging.basicConfig(level=logging.INFO, format = " %(message)s")

def max_counter(diffs):
    num = []
    for i in diffs:
        num.append(diffs.count(i))

    max_num = max(num)
    if max_num == 1:
        return 0
    else:
        return max_num
        
        
def main():
    N = int(input())
    
    balls = []
    for i in range(0, N):
        balls.append([int(x) for x in input().split()])

    ball_array = np.array(balls)    
    logging.info(ball_array)

    p_q = []
    for i in range(0, N - 1):
        diff = list(ball_array[i] - ball_array[i + 1])
        if 0 not in diff:
            p_q.append(diff)

    logging.info(p_q)
    print(N - max_counter(p_q))

          
if __name__ == "__main__":
    main()