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:
n = int(input())
xy = []
ans = []

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

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

for i in range(n):
    for j in range(i,n):
        if( i==j ):
            continue
        t = (xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
        ans.append(t)

res = [ans.count(e) for e in set(ans)]
print(n-max(res))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict

n = int(input())
pairs = list()
patterns = defaultdict(int)

for _ in range(n):
    pairs.append(tuple((map(int, input().split()))))

for i in range(n):
    for j in range(n):
        if i != j:
            patterns[(pairs[i][0] - pairs[j][0], pairs[i][1] - pairs[j][1])] += 1

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

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
c = []
for i in range(n):
    for j in range(i+1,n):
        x = s[j][0] - s[i][0]
        y = s[j][1] - s[i][1]
        c.append(str(x) + " " + str(y))
 
r = Counter(c)
q = list(r.values())
q1 = max(q)
print(n-q1)

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
l2 = []

for i in range(n):
    a, b = list(map(int, input().split()))
    l.append([a,b])

for i in range(len(l)):
    for j in range(i+1, len(l)+1):
        dif1 = l[i][0] - l[j][0]
        dif2 = l[i][1] - l[j][1]
        l2.append(str(dif1) + ' ' + str(dif2))
##print(l2)

try:
    cnt = max(l2, key=l2.count)
except:
    cnt = 0
x, y = list(map(int, cnt.split()))

ans = 0

for i in range(len(l)):
    if [l[i][0] + x, l[i][1] + y] in l:
        ans += 1

print(n - ans)

Submission status: Runtime Error

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

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

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

for i in range(n):
    for j in range(i,n):
        if( i==j ):
            continue
        t = (xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
        ans.append(t)

res = [ans.count(e) for e in set(ans)]
print(n-max(res))

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
l2 = []

for i in range(n):
    a, b = list(map(int, input().split()))
    l.append([a,b])

for i in range(len(l)):
    for j in range(i+1, len(l)):
        dif1 = l[i][0] - l[j][0]
        dif2 = l[i][1] - l[j][1]
        l2.append(str(dif1) + ' ' + str(dif2))
##print(l2)

try:
    cnt = max(l2, key=l2.count)
except:
    cnt = 0
x, y = list(map(int, cnt.split()))

ans = 0

for i in range(len(l)):
    if [l[i][0] + x, l[i][1] + y] in l:
        ans += 1

print(n - ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, x: "List[int]", y: "List[int]"):
    ds = []
    for i in range(N):
        for j in range(i + 1, N):
            dx = x[j] - x[i]
            dy = y[j] - y[i]
            ds.append((dx, dy))

    return N - max(Counter(ds).values())


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    result = solve(N, x, y)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]

t1 = []
for i in range(n):
    t1.append(str(s[i][0])+" "+str(s[i][1]))


t3 = Counter(t1)
t2 = list(set(t1))
c = []
for i in range(len(t2)):
    for j in range(i+1,n):
        x = abs(int(t2[j][0]) - int(t2[i][0]))
        y = abs(int(t2[j][2]) - int(t2[i][2]))
        e = min(t3[t2[i]],t3[t2[j]])
        for l in range(e):
            c.append(str(x) + " " + str(y))


r = Counter(c)
q = list(r.values())
q1 = max(q)
print(n-q1)

Submission status: Runtime Error

Solution code:
# 未完成
import numpy as np
N = int(input())
x = np.zeros(N)
y = np.zeros(N)

for i in range(N):
    x[i], y[i] = map(int, input().split())
for j in range(N):
    for k in range(N-1):
        if x[k] > x[k + 1]:
            x[k], y[k] = x[k + 1], y[k + 1]
        elif x[k] == x[k + 1] and y[k] > y[k + 1]:
            x[k], y[k] = x[k + 1], y[k + 1]

ans = np.zeros(N*N-N)
ite = 0
for m in range(N):
    for p in range(m):
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        for r in range(N-1):
            for q in range(r+1, N):
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans[ite] += 1
        ite += 1
ans_min = ans[0]
for z in range(ite):
    if ans_min < ans[z]:
        ans_min = ans[z]

print("{}".format(int(N-ans_min)))

Submission status: Runtime Error

Solution code:
n = int(input())
coord = []
for i in range(n):
    x, y = map(int, input().split())
    coord.append([x, y])
pravci = dict()
for i in range(n - 1):
    for j in range(i + 1, n):
#       k = delta y / delta x
        dy = coord[i][1] - coord[j][1]
        dx = coord[i][0] - coord[j][0]
        if dx == 0:
            if "x = " + str(coord[i][0]) in pravci:
                if not [coord[i][0], coord[i][1]] in pravci["x = " + str(coord[i][0])]:
                    pravci["x = " + str(coord[i][0])].append([coord[i][0], coord[i][1]])
                if not [coord[j][0], coord[j][1]] in pravci["x = " + str(coord[i][0])]:
                    pravci["x = " + str(coord[i][0])].append([coord[j][0], coord[j][1]])    
            else:
                pravci["x = " + str(coord[i][0])] = [[coord[i][0], coord[i][1]], [coord[j][0], coord[j][1]]]
            continue
        if dy == 0:
            if "y = " + str(coord[i][1]) in pravci:
                if not [coord[i][0], coord[i][1]] in pravci["y = " + str(coord[i][0])]:
                    pravci["y = " + str(coord[i][0])].append([coord[i][0], coord[i][1]])
                if not [coord[j][0], coord[j][1]] in pravci["y = " + str(coord[i][0])]:
                    pravci["y = " + str(coord[i][0])].append([coord[j][0], coord[j][1]])    
            else:
                pravci["y = " + str(coord[i][0])] = [[coord[i][0], coord[i][1]], [coord[j][0], coord[j][1]]]
            continue
        k = dy / dx
        if k in pravci:
            if not [coord[i][0], coord[i][1]] in pravci[k]:
                pravci[k].append([coord[i][0], coord[i][1]])
            if not [coord[j][0], coord[j][1]] in pravci[k]:
                pravci[k].append([coord[j][0], coord[j][1]])
        else:
            pravci[k] = [[coord[i][0], coord[i][1]], [coord[j][0], coord[j][1]]]
pravm = 0
pravac = 0
for i in pravci:
    if len(pravci[i]) > pravm:
        pravm = len(pravci[i])
        pravac = i
"""
print(pravac, pravm)
print()
for i in pravci:
    print(i, pravci[i])
"""
tocke = pravci[pravac]
pravci[pravac] = []
sol = 1
for i in pravci:
    for j in pravci[i]:
        if j not in tocke:
            tocke.append(j)
            sol += 1
# print()
print(sol)

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
l2 = []

for i in range(n):
    a, b = list(map(int, input().split()))
    l.append([a,b])

for i in range(len(l)):
    for j in range(i+1, len(l)):
        dif1 = l[i][0] - l[j][0]
        dif2 = l[i][1] - l[j][1]
        l2.append(str(dif1) + ' ' + str(dif2))
##print(l2)

try:
    cnt = max(l2, key=l2.count)
except:
    cnt = 0
x, y = list(map(int, cnt.split()))

ans = 0

for i in range(len(l)):
    if [l[i][0] - x, l[i][1] - y] in l:
        ans += 1

print(n - ans)

Submission status: Runtime Error

Solution code:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


N = int(input())
pair=defaultdict(int)
xy = []
for i in range(N):
    x,y = map(int,input().split())
    xy.append((x,y))
for i in range(N):
    for j in range(N):
        if i != j
        pair[(xy[j][0]-xy[i][0],xy[j][1]-xy[i][1])] += 1

m = 0
for v in pair.values():
    m = max(m,v)
print(N-m)

Submission status: Runtime Error

Solution code:
# coding: utf-8

import sys
def input(): return sys.stdin.readline().strip()

N = int(input())
# L = [int(x) for x in input().split()]
# N, M = map(int, input().split())
# S = input()

ball = [[int(x) for x in input().split()] for _ in range(N)]
dist = {}

for i, a in enumerate(ball):
    x0 = a[0]
    y0 = a[1]

    for j, b in enumerate(ball):
        x1 = b[0]
        y1 = b[1]

        xy = (x1-x0, y1-y0)

        if xy == (0, 0):
            continue

        if not xy in dist:
            dist[xy] = 1
        else:
            dist[xy] += 1
            
print(N - max(dist.values()))

Submission status: Runtime Error

Solution code:
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

N = int(input())						# 5

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

#print(P)


from itertools import permutations
from itertools import combinations
L = list(combinations(P, 2))
#print( L )
#print( len(L) )

A=[]

for l in L:
	a=l[1][0]-l[0][0]
	b=l[1][1]-l[0][1]
	A.append((a,b))

#print(A)


# 各朝食メニューの回数を調べる
from collections import defaultdict

d = defaultdict(int)
for b in A:
	d[b] += 1

#print(dict(d))
# => {'pan': 2, 'kome': 4, 'cereal': 1}

# Value降順
B=[]
for k, v in sorted(d.items(), key=lambda x: -x[1]):
	#print(str(k) + ": " + str(v))
	break

#print(k,v)

p=k[0]
q=k[1]

ans=0


def dellist(L, a, p,q):
	b = (a[0]-p, a[1]-q)
	c = (a[0]+p, a[1]+q)
	
	#print("__dellist, a,b,c", a,b,c)
	
	while b in L:
		L.remove(b)
		dellist(L, b, p,q)

	while c in L:
		L.remove(c)
		dellist(L, c, p,q)
	
	while a in L:
		L.remove(a)
	


while len(A)>0:
	a = A[0]
	ans+=1
	#print(ans, a, A)
	dellist(A, a, p, q)
	


print(ans)

Submission status: Runtime Error

Solution code:
# # -*- coding: utf-8 -*-
N=int(input())
X=[]
Y=[]
for _ in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
Z=[]
for i in range(N):
    for j in range(i+1,N):
        Z=Z+[(abs(X[i]-X[j]),abs(Y[i]-Y[j]))]
import collections
z=collections.Counter(Z)
print(N-z.most_common()[0][1])

Submission status: Runtime Error

Solution code:
n=int(input())
r=[]
a=[]
for i in range(n):
  b,c=(int(j) for j in input().split())
  for k in range(i):
    d=a[k][0]-b
    e=a[k][1]-c
    if d<0:
      d=-d
      e=-e
    r.append([d,e])
  a.append([b,c])
for j in range(n):
  for i in range(n):
    if a[i][0]>a[i+1][0]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
    elif a[i][1]>a[i+1][1]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
sortsecond = lambda val: val[1]
a.sort(key=sortsecond)
r.sort()
if n>1:
  p=r[0]
x=1
z=0
t=0
q=[]
for i in range(len(r)-1):
  if r[i]==r[i+1]:
    x=x+1
    if x>z:
      p=r[i]
      z=x
  else:
    x=1
if n==1:
  print(1)
else:
  for i in range(n):
    if a[i] not in q:
      t=t+1
    q.append([a[i][0]+p[0],a[i][1]+p[1]])
    q.append([a[i][0]-p[0],a[i][1]-p[1]])
  print(t)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
arr = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

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

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

C = []
for i in range(N):
    for j in range(N):
        if i < j:
            x = arr[i][0]-arr[j][0]
            y = arr[i][1]-arr[j][1]
            C.append([x, y])


C = get_unique_list(C)
S = [0 for i in range(len(C))]

for c in range(len(C)):
    tmp = [[[arr[0][0], arr[0][1]]]]
    for i in range(1, N):
        l = len(tmp)
        for j in range(l):
            for k in range(len(tmp[j])):
                x_t = tmp[j][k][0] - arr[i][0]
                y_t = tmp[j][k][1] - arr[i][1]
                arr_i = [arr[i][0], arr[i][1]]
                if C[c][0] == 0 and y_t%C[c][1] == 0:
                    if x_t == 0:
                        tmp[j].append(arr_i)
                        break
                    elif j == l - 1:
                        tmp.append(arr_i)
    
                elif C[c][1] == 0 and x_t%C[c][0] == 0:
                    if y_t == 0:
                        tmp[j].append(arr_i)
                        break
                    elif j == l - 1:
                        tmp.append(arr_i)
                else:
                    if x_t*C[c][1] == y_t*C[c][0]:
                        tmp[j].append(arr_i)
                        break
                    elif j == l - 1:
                        tmp.append(arr_i)
                        
    S[c] = len(tmp)
    
print(min(S))

Submission status: Runtime Error

Solution code:

import collections
N = int(input())

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

ans = 0
for i in range(N):
    x_ = [x[j]-x[i] for j in range(N)]
    y_ = [y[j]-y[i] for j in range(N)]
    for k in range(N):
        prop = []
        if x_[k] != 0:
            prop.append(y_[k]/x_[k])
    c = collections.Counter(prop)
    tmp = max(c.values())
    if tmp > ans:
        ans = tmp

print(N-ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict as de
s=de(int)
u=de(int)
n=int(input())
a=sorted([list(map(int,input().split()))for i in range(n)])
for i in range(n):
    u.append(a[i])
    for j in range(n):
        if i!=j:
            s[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
p,q=max([(v,k) for k,v in s.items()])[1]
i=0
p=n-1
g=0
while i!=n:
    if u[a[n-1]]>0:
        u[a[n-1]]-=1
    s,t=a[n-1][0]-p,a[n-1][1]-q
    i+=1
    while u[s,t]>0:
        u[s,t]-=1
        s-=p
        t-=q
        i+=1
    else:
        g+=1
print(g)

Submission status: Runtime Error

Solution code:
# 何本の数直線上にあるかを求める　1<=ans<=n-1
# 少なくとも2点を通る直線のみ調べれば良い
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
xy.sort(key=lambda x:(x[0],x[1]))
# print(xy)
if n<=2:
    print(1)
else:
    diff=[]
    for i in range(n):
        for j in range(i):
            diff.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))

    ans=[]
    # print(set(diff))
    for p,q in set(diff):
        intercept=[]
        for i in range(n):
            qxHIKUpy=q*xy[i][0]-p*xy[i][1]
            intercept.append(qxHIKUpy)
        # print(q,'x-',p,'y=',intercept)
        intercepts=sorted(enumerate(intercept),key=lambda x:x[1])
        intercept=set(intercept)
        # print(intercepts)
        i=0
        cnt=len(intercept)
        for b in intercept:
            x=0
            if intercepts[i][1]==b:
                x=xy[intercepts[i][0]][0]
            i+=1
            while intercepts[i][1]==b:
                if x+p!=xy[intercepts[i][0]][0]:
                    cnt+=1
                x=xy[intercepts[i][0]][0]
                i+=1
                if i==n:
                    break

        ans.append(cnt)
    # print(ans)
    print(min(ans))

Submission status: Runtime Error

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

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

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

for i in range(n):
    for j in range(i,n):
        if( i==j ):
            continue
        t = (xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
        #renso[t]=renso.get(t,0)+1
        ans.append(t)

res = max([ans.count(e) for e in set(ans) if ans.count(e) > 1])
print(n-res)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
if N == 1 or N ==2:
    print("1")
else:
    L = []
    for i in range(N):
        [x, y] = map(int, input().split())
        L.append([x, y])
    L.sort()
    
    
    
    difL = []
    for i in range(N-1):
        [difx, dify] = L[i+1][0]-L[i][0], L[i+1][1]-L[i][1]
        difL.append([difx, dify])

    t = map(tuple, difL)
    counted = collections.Counter(t)
    print(N-counted.most_common()[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]

t1 = []
for i in range(n):
    t1.append(str(s[i][0])+" "+str(s[i][1]))


t3 = Counter(t1)
t2 = list(set(t1))
c = []
for i in range(len(t2)):
    for j in range(i+1,n):
        x = int(t2[j][0]) - int(t2[i][0])
        y = int(t2[j][2]) - int(t2[i][2])
        e = min(t3[t2[i]],t3[t2[j]])
        for i in range(e):
            c.append(str(x) + " " + str(y))

r = Counter(c)
q = list(r.values())
q1 = max(q)
print(n-q1)

Submission status: Runtime Error

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

  from itertools import permutations

  pre = []
  ans = int(1e9+7)
  for comb in permutations(XY):
    cost = 1
    p = comb[0][0] - comb[1][0]
    q = comb[0][1] - comb[1][1]
    for a, b in comb:
      if not pre:
        pre = (a, b)
        continue
      if (a - p, b - q) == pre:
        pass
      else:
        cost += 1
      pre = (a, b)
    ans = min(ans, cost)
    pre = []
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
pqn = {}
for i in range(N-1):
  for j in range(i+1,N):
    dp = A[i][0] -A[j][0]
    dq = A[i][1] -A[j][1]
    if str([dp,dq]) in pqn.keys():
      pqn[str([dp,dq])] += 1
    else:
      pqn[str([dp,dq])] = 1
a = N-max(pqn.values())
print(a if a>0 else 1)

Submission status: Runtime Error

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

dx = [[10**10]*N for _ in [0]*N]
dy = [[10**10]*N for _ in [0]*N]
ps = set()
qs = set()
for i in range(N):
    for j in range(N):
        if i==j:continue
        dx[i][j] = xy[i][0] - xy[j][0]
        dy[i][j] = xy[i][1] - xy[j][1]
        ps.add(dx[i][j])
        qs.add(dy[i][j])
for i in range(N):
    dx[i] = set(dx[i]) - set(10**10)
    dy[i] = set(dy[i]) - set(10**10)

ans = 0
for p in ps:
    for q in qs:
        cnt = 0
        for i in range(N):
            if (p in dx[i]) and (q in dy[i]):
                cnt += 1
        ans = max(ans,cnt)

print(N-ans)

Submission status: Runtime Error

Solution code:
n = int(input())
mapp = []
score = []
for i in range(n):
    x, y = [int(i) for i in input().split()]
    mapp.append([x, y])
for i in range(n-1):
    aaa = 1
    p = mapp[i+1][0] - mapp[i][0]
    q = mapp[i+1][1] - mapp[i][1]
    for j in range(n-1):
        if(mapp[j+1][0] - p ==  mapp[j][0] and mapp[j+1][1] - q == mapp[j][1]):
            aaa += 0
        else:
            aaa += 1
    score.append(aaa)
print(min(score))

Submission status: Runtime Error

Solution code:
# 2019/06/15
# diverta 2019 Programming Contest 2 - B

from operator import itemgetter

# Input
n = int(input())
xylist = list()

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

xydist = list()

for i in range(n-1):
    for j in range(i+1, n):
        wx = abs(xylist[i][0] - xylist[j][0])
        wy = abs(xylist[i][1] - xylist[j][1])
        xydist.append([wx, wy])

xydist.sort()
maxcnt = 0
p = -1
q = -1
cnt = 1
for l in range(1, len(xydist)):
    if xydist[l] != xydist[l-1]:
        if maxcnt < cnt:
            maxcnt = cnt
            p = xydist[l-1][0]
            q = xydist[l-1][1]
        cnt = 1
    else:
        cnt += 1

if maxcnt < cnt:
    maxcnt = cnt
    p = xydist[len(xydist)-1][0]
    q = xydist[len(xydist)-1][1]

xylist.sort()

ans = 0
for i in range(len(xylist)):
    wx = xylist[i][0] + p
    wy = xylist[i][1] + q

    for j in range(i+1, len(xylist)):
        if xylist[j][0] == wx and xylist[j][1] == wy:
            ans -= 1
            break

    ans += 1

# Output
print(ans)

Submission status: Runtime Error

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

d=[]
dX=[]
dY=[]

minCost = 0

for f in range(N):
  for t in range(N):
    if f == t:
      continue
    else:
      p = x[t] - x[f]
      q = y[t] - y[f]
      
      xf = x[t]
      yf = y[t]
      cost = 0
      while 1 == 1:
        xn = xf + p
        yn = yf + q
        if xn > max(x) or xn < min(x):
          cost += 1
          break
        if yn > max(y) or yn < min(y):
          cost += 1
          break
        ix = x.index(xn)
        iy = y.index(yn)
        if ix != iy:
          cost += 1
          
        xf = xn
        yf = yn
        
      if minCost < cost:
        minCost = cost
        
print(minCost + 1)

Submission status: Runtime Error

Solution code:
N = int(input())

List = list(list(map(int, input().split())) for o 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)):
    # if(Data[k] == [0,0]):
    #     continue
    # else:
    #     Duplicate.append(Data.count(Data[k]))
    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())
a=[]
for i in range(0,n):
  b,c=map(int,input().split())
  a.append([b,c])
for i in range(0,len(a)-1):
  for k in range(i+1,len(a)):
    d.append([a[k][0]-a[i][0],a[k][1]-a[i][1]])
count=0
for i in range(0,len(d)):
  if count(d[i])>count:
  	count=count(d[i])
print(n-count)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())

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

xy.sort()

pi = [[] for i in range(n//2)]
qi = [[] for i in range(n//2)]

for k in range(n//2):
	for i in range(n-1-k):
		pi[k].append(xy[i][0] - xy[i+k+1][0])
		qi[k].append(xy[i][1] - xy[i+k+1][1])

if n//2 == 1:
	pc = collections.Counter(pi[0])
	qc = collections.Counter(qi[0])

	lpc = len(pc.keys())
	lqc = len(qc.keys())
	print(max(lpc,lqc))
else:
	l = []
	for i in range(n//2):
		pci = collections.Counter(pi[i])
		qci = collections.Counter(qi[i])
		l.append(max(len(pci.keys()),len(qci.keys())))
	print(max(l))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
A.sort()

xlog = []
ylog = []
minus = 0
for i in range(N):
	if A[i] < 0:
		minus += 1

i = 0
a = A[0]
if N >= 3:
	x = A[N-1-i]
	y = A[i]
	a = x - y
	xlog.append(x)
	ylog.append(y)
cnt = 0

for i in range(N-3):
	if a > A[i+1]:
		x = A[i+1]
		y = a
	else:
		x = a
		y = A[i+1]
	a = x - y
	xlog.append(x)
	ylog.append(y)
	cnt += 1

if a < A[i+1]:
	x = A[i+1]
	y = a
else:
	x = a
	y = A[i+1]
a = x - y

xlog.append(x)
ylog.append(y)

m = a
print(m)
for i in range(N-1):
	print(xlog[i], ylog[i])

Submission status: Runtime Error

Solution code:
import collections

n = int(input())

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

xy.sort()

pi = [[] for i in range(n//2)]
qi = [[] for i in range(n//2)]

for k in range(n//2):
	for i in range(n-1-k):
		pi[k].append(xy[i][0] - xy[i+k+1][0])
		qi[k].append(xy[i][1] - xy[i+k+1][1])

if n//2 == 1:
	pc = collections.Counter(pi[0])
	qc = collections.Counter(qi[0])

	lpc = len(pc.keys())
	lqc = len(qc.keys())
	print(max(lpc,lqc))
else:
	l = []
	for i in range(n//2):
		pci = collections.Counter(pi[i])
		qci = collections.Counter(qi[i])
		l.append(max(len(pci.keys()),len(qci.keys())))
	print(max(l)+1)

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

d = []
e = []

for i in range(N-1):
    for j in range(i+1,N):
        p = (x[i]-x[j])
        q = (y[i]-y[j])

        a = [p,q]
        d.append(a)

max = 0

for i in range(i*j):
    if max < d.count(d[i])+d.count(d[i]*(-1)):
        max = d.count(d[i])+d.count(d[i]*(-1))

if max == N:
    max = N-1

print(N-max)

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=[]
sa_uniq=[]
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])
  if [sax,say] not in sa_uniq:
    sa_uniq.append([sax,say])

count = []
for sa in sa_uniq:
  count.append(salist.count(sa))

if N-max(count)==0:
  print('1')
else:
  print(N-max(count))

Submission status: Runtime Error

Solution code:
import collections
 
N=int(input())
x=[0]*N
y=[0]*N
a=[]
b=[]
c=1
for i in range(N):
  x[i], y[i]=map(int, input().split())
  
for n in range(1,N):
  a.append(x[n]-x[n-1])
  b.append(y[n]-y[n-1])

X=collections.Counter(a).most_common()[0][1]
Y=collections.Counter(b).most_common()[0][1]

X=0 if X==1 else X
Y=0 if Y==1 else Y
print(max(N-X,N-Y))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
pqn = {}
for i in range(N-1):
  for j in range(i+1,N):
    dp = A[i][0] -A[j][0]
    dq = A[i][1] -A[j][1]
    if str([dp,dq]) in pqn.keys():
      pqn[str([dp,dq])] += 1
    else:
      pqn[str([dp,dq])] = 1
print(N-max(pqn.values()))

Submission status: Runtime Error

Solution code:
from collections import Counter
N=int(input())
listX=[]
listY=[]
listP=[]
listQ=[]
listR=[]
listS=[]
for i in range(N):
  x,y=map(int,input().split())
  listX+=[x]
  listY+=[y]
if listX!=set(listX):  
  for i in range(N):
    for k in range(N):
      if i>k:
        listP+=[(listY[i]-listY[k])/(listX[i]-listX[k])]
  counter1=Counter(listP)
  for word, cnt in counter1.most_common():
    listQ+=[cnt]
  A=max(listQ)
  print(N-A+1)  
else:    
  counter2=Counter(listX)
  for word, cnt in counter1.most_common():
    listR+=[cnt]
  for i in range(N):
    for k in range(N):
      if i>k and listX[i]!=listX[k]:
        listS+=[(listY[i]-listY[k])/(listX[i]-listX[k])]
  counter3=Counter(listS)
  for word, cnt in counter3.most_common():
    listR+=[cnt]  
  A=max(listQ)
  print(N-A+1)

Submission status: Runtime Error

Solution code:
import itertools
import collections

N = int(input())

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

combinations = list(itertools.combinations(dict_xy, 2))
# combinations = list(itertools.permutations(dict_xy, 2))
relative_coordinates = []

for combination in combinations:
    key1 = combination[0]
    key2 = combination[1]

    x1 = dict_xy[key1][0]
    y1 = dict_xy[key1][1]
    x2 = dict_xy[key2][0]
    y2 = dict_xy[key2][1]

    if x1 + y1 > x2 + y2:
        x1, y1, x2, y2 = x2, y2, x1, y1
    elif x1 + y1 == x2 + y2 and x1 > x2:
        x1, y1, x2, y2 = x2, y2, x1, y1

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

counter = collections.Counter(relative_coordinates)
cost = N - counter.most_common()[0][1]
print(cost)

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)):
    # if(Data[k] == [0,0]):
    #     continue
    # else:
    #     Duplicate.append(Data.count(Data[k]))
    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())
A = [list(map(int,input().split())) for _ in range(N)]
pqn = {}
for i in range(N-1):
  for j in range(i+1,N):
    dp = A[i][0] -A[j][0]
    dq = A[i][1] -A[j][1]
    if str([dp,dq]) in pqn.keys():
      pqn[str([dp,dq])] += 1
    else:
      pqn[str([dp,dq])] = 1
print(pqn)
print(N-max(pqn.values()))

Submission status: Runtime Error

Solution code:

N = int(input())
t = [0] * N
x = [0] * N
for i in range(N):
    t[i], x[i] = map(int, input().split())
p1, q1 = t[0]-t[1], x[0]-x[1]
p2, q2 = -(t[-1]-t[-2]), -(x[-1]-x[-2])
cost1 = 1
cost2 = 1
for i in range(N-1):
    if t[i+1] !=  (t[i]-p1) and x[i+1] != (x[i]-q1):
        cost1 += 1
for i in reversed(range(N)):
    print(t[i-1], t[i])
    if t[i-1] !=  (t[i]-(-p2)) and x[i-1] != (x[i]-(-q2)) and i != 0:
        cost2 += 1

print(min(cost1, cost2))

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

d = []
e = []

for i in range(N-1):
    for j in range(i+1,N):
        p = (x[i]-x[j])
        q = (y[i]-y[j])

        a = [p,q]
        d.append(a)

max = 0

for i in range(N):
    if max < d.count(d[i])+d.count(d[i]*(-1)):
        max = d.count(d[i])+d.count(d[i]*(-1))

if max == N:
    max = N-1

print(N-max)

Submission status: Runtime Error

Solution code:
print "1"

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
list_ = [tuple(map(int, input().split())) for i in range(n)]
list_.sort()

ab = []
for i in range(len(list_)-1):
    x_1, y_1 = list_[i]
    
    for j in range(i+1, len(list_)):
        x_2, y_2 = list_[j]
        a = x_2 - x_1
        b = y_2 - y_1
        ab.append((a, b))

p, q = Counter(ab).most_common()[0][0]

res = 0
while len(list_):
    res += 1
    x, y = list_.pop(0)
    while True:
        if (x+p, y+q) in list_:
            list_.remove((x+p, y+q))
            x, y = x+p, y+q
        else:
            break

print(res)