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: Wrong Answer

Solution code:
from fractions import Fraction


class PickingUp:
    def __init__(self):
        self.N = int(input())
        self.points = []
        for n in range(self.N):
            self.points.append([int(n) for n in input().split()])

    def main(self):
        pattern_list = []
        slope_list = []
        for s in range(self.N):
            section_list = []
            for e in range(s + 1, self.N):
                slope = self.__cal_slope(self.points[s], self.points[e])
                if slope not in slope_list:
                    slope_list.append(slope)

        for sl in slope_list:
            for i in range(self.N):
                section = self.__cal_section(sl, self.points[i])
                if section not in section_list:
                    section_list.append(section)
            pattern_list.append(len(section_list))

        if len(pattern_list) == 0:
            pattern_list.append(1)

        print(min(pattern_list))

    def __cal_slope(self, s, e):
        if s[0] != e[0]:
            return Fraction((s[1] - e[1]), (s[0] - e[0]))
        else:
            return None

    def __cal_section(self, slope, point):
        if slope is not None:
            return point[1] - slope * point[0]
        else:
            return point[0]


pickingUp = PickingUp()
pickingUp.main()

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
n = int(input())

li = []

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

li.sort()

def cal(li):
    n = len(li)
    Route = []
    for s in range(n-1):
        x1, y1 = li[s]
        route = {}
        for i in range(n):
            xi, yi = li[i]
            if i != s:
                if i < s:
                    A1 = x1; A2 = y1
                    B1 = xi; B2 = yi
                else:
                    B1 = x1; B2 = y1
                    A1 = xi; A2 = yi
                     
                if A2 != A1:
                    diff = Fraction((B2 - B1),(A2 - A1))
                else:
                    diff = 10e10

                if diff in route.keys():
                    route[diff].append([xi, yi])
                else:
                    route[diff] = [[x1,y1], [xi, yi]]

        Route.extend(route.values())
    return Route

cost = 0
route = cal(li)

def check(A,B):
    for a in A:
        if a not in B:
            return False
    
    return True

def max_cal(route, li):
    n = len(li)
    l_max = 0
    max_li = []
    for r in route:
        if check(r,li):
            l = len(r)
            if l > l_max:
                 max_li = r
                 l_max = l
    return l_max, max_li

while True:
    l, cand = max_cal(route, li)
    if l == 0:
        cost += len(li)
        break
    else:
        route.remove(cand)
        for c in cand:
            li.remove(c)
        cost += 1
    if len(li) == 0:
        break

print(cost)

Submission status: Wrong Answer

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


ans = 0
for m in range(N):
    for p in range(m+1, N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = 0
        for r in range(N):
            for q in range(r+1, N):
                if r == q:
                    continue
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari += 1
        if ans_kari > ans:
            ans = ans_kari

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

Submission status: Wrong Answer

Solution code:
from fractions import Fraction


class PickingUp:
    def __init__(self):
        self.N = int(input())
        self.points = []
        for n in range(self.N):
            self.points.append([int(n) for n in input().split()])

    def main(self):
        pattern_list = []
        slope_list = []
        for s in range(self.N):
            section_list = []
            for e in range(s + 1, self.N):
                slope = self.__cal_slope(self.points[s], self.points[e])
                if slope not in slope_list:
                    slope_list.append(slope)

        for sl in slope_list:
            for i in range(self.N):
                section = self.__cal_section(slope, self.points[i])
                if section not in section_list:
                    section_list.append(section)
            pattern_list.append(len(section_list))

        if len(pattern_list) == 0:
            pattern_list.append(1)

        print(min(pattern_list))

    def __cal_slope(self, s, e):
        if s[0] != e[0]:
            return Fraction((s[1] - e[1]), (s[0] - e[0]))
        else:
            return None

    def __cal_section(self, slope, point):
        if slope is not None:
            return point[1] - slope * point[0]
        else:
            return point[0]


pickingUp = PickingUp()
pickingUp.main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

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

dc_c = []
dc_c = []
dc_ans = []
for i in range(n):
    ii = 0
    d = [[-1]*2 for i in range(n)]
    for j in range(n):
        if i != j:
            d[ii][0] = abs(x[i]-x[j])
            d[ii][1] = abs(y[i]-y[j])
            ii += 1
    dc = Counter(map(tuple, d))
    dc_ans = Counter(dc_ans) + dc
dc_ans = dc_ans.most_common()
if dc_ans[0][0] == (-1, -1):
    print(n-dc_ans[1][1])
else:
    print(n-dc_ans[0][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 1
max = -99999
ruiseki_x = []
ruiseki_y = []
list_x = []
list_y = []
sort_list = []
for i in range(N):
    x,y = map(int,input().split())
    list_x.append(x)
    list_y.append(y)
for i in range(1,N):
    ruiseki_x.append(list_x[i-1] - list_x[i])
    ruiseki_y.append(list_y[i-1] - list_y[i])
c = list(zip(ruiseki_x,ruiseki_y))
count = 0
for i in range(len(c)):
    count = 0
    for j in range(len(c)):
        if c[i] == c[j]:
            count += 1
    if max < count:
        max = count
print((len(c) + 1) - max)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
ans=n
for i in range(n):
  for j in range(i+1,n):
    p,q=arr[j][0]-arr[i][0],arr[j][1]-arr[i][1]
    if p==0 and q==0:
      continue
    cnt=0
    flag=[0]*n
    for k in range(n):
      if flag[k]==1:
        continue
      flag[k]=1
      tmp=1
      for l in range(k,n):
        check=0
        if p==0:
          if arr[l][0]==arr[k][0]:
            check+=1
        elif p>0:
          if (arr[l][0]-arr[k][0])>0 and (arr[l][0]-arr[k][0])%p==0:
            check+=1
        else:
          if (arr[l][0]-arr[k][0])<0 and (arr[l][0]-arr[k][0])%p==0:
            check+=1
        if q==0:
          if arr[l][1]==arr[k][1]:
            check+=1
        elif q>0:
          if (arr[l][1]-arr[k][1])>0 and (arr[l][1]-arr[k][1])%q==0:
            check+=1
        else:
          if (arr[l][1]-arr[k][1])<0 and (arr[l][1]-arr[k][1])%q==0:
            check+=1
        if check==2:
          flag[l]=1
      cnt+=1
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
xys=[list(map(int,input().split())) for _ in range(n)]
li = [[0,0] for i in range(n*(n-1)//2)]
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        li[cnt][0] = xys[i][0] - xys[j][0]
        li[cnt][1] = xys[i][1] - xys[j][1]
        cnt += 1

li.sort()
ans = 0
cnt = 1
for i in range(len(li)-1):
    if li[i][0] == li[i+1][0] and li[i][1] == li[i+1][1]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt =1
ans = max(ans,cnt)
print(n-ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 1
max = -99999
ruiseki_x = []
ruiseki_y = []
list_x = []
list_y = []
sort_list = []
for i in range(N):
    x,y = map(int,input().split())
    list_x.append(x)
    list_y.append(y)
for i in range(1,N):
    ruiseki_x.append(list_x[i-1] - list_x[i])
    ruiseki_y.append(list_y[i-1] - list_y[i])
c = list(zip(ruiseki_x,ruiseki_y))
count = 0
for i in range(len(c)):
    count = 0
    for j in range(len(c)):
        if c[i] == c[j]:
            count += 1
    if max < count:
        max = count
print(len(c) - max)

Submission status: Wrong Answer

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


ans = 0
for m in range(N):
    for p in range(N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = 0
        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_kari += 1
        if ans_kari > ans:
            ans = ans_kari

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

Submission status: Wrong Answer

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

PQ = []
# 2点を選びp,q仮決め
for i in range(N):
    prev = XY[i]
    for j in range(N):
        if i!=j:
            next = XY[j]
            p = next[0] - prev[0]
            q = next[1] - prev[1]
            PQ.append((p,q))

ans = 1
for pq in PQ:
    ans = max(ans, PQ.count(pq))
print(N - ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
arr = [list(map(int, input().rstrip().split())) for _ in range(n)]
cnt = {}
for i in range(n):
    for j in range(i + 1, n):
        dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt.setdefault(dif, 0)
        cnt[dif] += 1
print(1 if cnt == {} else n - max(cnt.values()))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

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

for i in range(0,n):
    x,y = input().split()
    coordinates.append((int(x), int(y) ))

coordinates = sorted(coordinates, key = lambda coordinate: (-coordinate[0], -coordinate[1] ))

diff = []
oldCoordinate = (0,0)

for coordinate in coordinates :
    diff.append( ( oldCoordinate[0] - coordinate[0], oldCoordinate[1]- coordinate[1] ) )
    oldCoordinate = coordinate

count = []
i = 0
for d in diff :
    cnt = 0

    for dCheck in diff :
        if d == dCheck and i!=0 :
            cnt += 1
    
    i+=1
    count.append(cnt)

maxCount = np.amax( np.array(count) )

print( n - maxCount)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 20:54:29 2019

@author: Yamazaki Kenichi
"""

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

a = []
for j in range(N):
    for i in range(N):
        if (A[i][1] - A[j][1]) == 0 or (A[i][0] - A[j][0]) == 0:
            continue
        a.append([A[i][1] - A[j][1], A[i][0] - A[j][0]])

a.sort()
same = 0
ans = 0
for i in range(1,len(a)):
    if a[i-1] == a[i]:
        same += 1
    else:
        same = 0
    ans = max(ans, same)
print(N - ans -1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
li = []
if N == 1:
    a = list(map(int,input().split()))
    print(0)
    sys.exit()   

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]]
        if a[0] <= 0 and a[1] <= 0:
            b = [abs(li[j][0]-li[i][0]),abs(li[j][1]-li[i][1])]
            cross.append(b)
        elif a[0] < 0 and a[1] >= 0:
            c = li[j][1]-li[i][1]
            b = [abs(li[j][0]-li[i][0]),-c]
            cross.append(b) ####
        else:
            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)
reduce = max(ans)

print(N - reduce)

Submission status: Wrong Answer

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])
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
for j in range(n-1):
  for i in range(n-1):
    if a[i][0]>a[i+1][0]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
    elif a[i][0]==a[i+1][0]:
      if (a[i][1]-a[i+1][1])*p[1]>0:
        w=a[i]
        a[i]=a[i+1]
        a[i+1]=w
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]])
  print(t)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

A = []

for i in range(n):
    A.append(list(map(int, input().split())))

A = np.array(A)

X = np.eye(n, k = 1, dtype = int)
X[n-1, 0] = 1

B = []
a = np.copy(A)

for i in range(n-1):
    a = np.dot(X, a)
    B.append(A - a)

B = np.array(B)

B = np.reshape(B, (-1, 2))

B = B[np.argsort(B[:, 1])]
B = B[np.argsort(B[:, 0])]

c = 1
max_cont = 1
for i in range(1, B.shape[0]):
    if B[i][0] == B[i-1][0] and B[i][1] == B[i-1][1]:
        c += 1
    elif c > max_cont:
        max_cont = c
        c = 1
    else:
        c =1

print(n - max_cont)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction

n = int(input())

li = []

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

li.sort()

def cal(li):
    n = len(li)
    Route = []
    for s in range(n-1):
        x1, y1 = li[s]
        route = {}
        for i in range(s+1,n):
            xi, yi = li[i]

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

            if diff in route.keys():
                route[diff].append([xi, yi])
            else:
                route[diff] = [[x1,y1], [xi, yi]]

        Route.extend(route.values())
    return Route

cost = 0
route = cal(li)

def check(A,B):
    for a in A:
        if a not in B:
            return False
    
    return True

def max_cal(route, li):
    n = len(li)
    l_max = 0
    max_li = []
    for r in route:
        if check(r,li):
            l = len(r)
            if l > l_max:
                 max_li = r
                 l_max = l
    return l_max, max_li

while True:
    l, cand = max_cal(route, li)
    if l == 0:
        cost += len(li)
        break
    else:
        route.remove(cand)
        for c in cand:
            li.remove(c)
        cost += 1
    if len(li) == 0:
        break

print(cost)

Submission status: Wrong Answer

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

PQ = []
# 2点を選びp,q仮決め
for i in range(N):
    prev = XY[i]
    for j in range(N):
        if i==j: continue
        next = XY[j]
        p = next[0] - prev[0]
        q = next[1] - prev[1]
        PQ.append([p,q])

ans = 0
for pq in PQ:
    ans = max(ans, N-PQ.count(pq)-1)
print(ans)

Submission status: Wrong Answer

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 = 0
for m in range(N):
    for p in range(m):
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = 0
        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_kari += 1
        if ans_kari > ans:
            ans = ans_kari

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

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
if N == 1:
    print(1)
    exit()

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

t = []
for i in range(N-1):
    for j in range(i+1, N):
        t.append((xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]))
c = collections.Counter(t)
print(ans-c.most_common()[0][1])

Submission status: Wrong Answer

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

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        if xy[i][0]-xy[j][0]<=0:
            list_.append((-(xy[i][0]-xy[j][0]),-(xy[i][1]-xy[j][1])))
        else:
            list_.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))

if N==1:
    print(1)
else:
    print(N-Counter(list_).most_common()[0][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
X = []
Y = []
Z = []
ans = 0
for i in range(N):
    x[i], y[i] = map(int, input().split())

for k in range(N-1):
    for i in range (N-k-1): 
        X.append(abs(x[k]-x[k+i+1]))

for k in range(N-1):
    for i in range (N-k-1): 
        Y.append(abs(y[k]-y[k+i+1]))

for i in range(len(X)):
    Z.append([X[i], Y[i]])

for i in range(len(Z)):
    if ans < Z.count(Z[i]):
        ans = Z.count(Z[i])

print(N-ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
w={}
d=[]
for i in range(n):
    x,y=map(int, input().split())
    d.append((x,y))

chk=0
for i in range(n-1):
    a=d[i][0]
    b=d[i][1]
    for j in range(i+1,n):
        p=d[j][0]
        q=d[j][1]
        if (a-p,b-q) in w:
            w[(a-p,b-q)]+=1
        else:
            w[(a-p,b-q)]=1
        chk=max(chk,w[(a-p,b-q)])
print(n-chk)

Submission status: Wrong Answer

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 = 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 += 1

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

Submission status: Wrong Answer

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 1 if N == 1 else (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: Wrong Answer

Solution code:
N = int(input())

balls = [[0]*2 for i in range(N)]

for i in range(N):
    balls[i][0], balls[i][1] = list(map(int, input().split()))

balls = sorted(balls, key=lambda x: x[0])
print(balls)

#1個のときは別に処理を書くこと

common_b = 0

for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        if balls[j][0]-balls[i][0] != 0:
            slope = (balls[j][1]-balls[i][1]) / (balls[j][0]-balls[i][0])

            for k in range(N):
                for l in range(k+1, N):
                    if balls[k][0]-balls[l][0] == 0:
                        continue
                    
                    slope2 = (balls[k][1]-balls[l][1]) / (balls[k][0]-balls[l][0])
                    if slope == slope2 and (i != k or j != k):
                        tmp+=1

        else:
            for k in range(N):
                for l in range(k+1, N):
                    if balls[k][0]-balls[l][0] == 0 and (i != k or j != k):
                        tmp += 1
                        continue
                    
        common_b = max(common_b, tmp)

print(N - common_b)

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    if n ==1:
        print(1)
    else:
        x_y_list=[]
        for i in range(n):
            x,y = map(int,input().split(' '))
            x_y_list.append((x,y))
        sorted_x_y = sorted(x_y_list,reverse=True)
        p_q_list=[]
        for i in range(n-1):
            for j in range(i,n):
                dif_x = sorted_x_y[i][0]-sorted_x_y[j][0]
                dif_y = sorted_x_y[i][1]-sorted_x_y[j][1]
                if dif_x != 0 and dif_y != 0:
                    p_q_list.append((dif_x,dif_y))
        p_q_list = list(set(p_q_list))
        p_q_max = 1
        for p,q in p_q_list:
            for i in range(n):
                tmp = 1
                x_i = sorted_x_y[i][0]
                y_i = sorted_x_y[i][1]
                for j in range(n):
                    if i ==j:
                        continue
                    x_j = sorted_x_y[j][0]
                    y_j = sorted_x_y[j][1]
                    if (x_j-x_i)%p == 0  and (y_j-y_i)%q == 0:
                        tmp += 1
                if tmp > p_q_max:
                    p_q_max = tmp
        print(n-p_q_max+1)

main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i in range(n):
    for j in range(i + 1, n):
        dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt.setdefault(dif, 0)
        cnt[dif] += 1
print(0 if cnt == {} else n - max(cnt.values()))

Submission status: Wrong Answer

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

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        if xy[i][0]-xy[j][0]<=0:
            list_.append((abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))
        else:
            list_.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))

if N==1:
    print(1)
else:
    print(N-Counter(list_).most_common()[0][1])

Submission status: Wrong Answer

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)
  B=listQ.count(A)
  print(N-A*B+1)  
else:    
  counter2=Counter(listX)
  for word, cnt in counter2.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(listR)
  B=listR.count(A)
  print(N-A*B+1)

Submission status: Wrong Answer

Solution code:
n = int(input())

li = []

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

li.sort()

def cal(li):
    n = len(li)
    Route = []
    for s in range(n-1):
        x1, y1 = li[s]
        route = {}
        for i in range(s+1,n):
            xi, yi = li[i]

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

            if diff in route.keys():
                route[diff].append([xi, yi])
            else:
                route[diff] = [[x1,y1], [xi, yi]]

        Route.extend(route.values())
    return Route

cost = 0
route = cal(li)

def check(A,B):
    for a in A:
        if a not in B:
            return False
    
    return True

def max_cal(route, li):
    n = len(li)
    l_max = 0
    max_li = []
    for r in route:
        if check(r,li):
            l = len(r)
            if l > l_max:
                 max_li = r
                 l_max = l
    return l_max, max_li

while True:
    l, cand = max_cal(route, li)
    if l == 0:
        cost += len(li)
        break
    else:
        route.remove(cand)
        for c in cand:
            li.remove(c)
        cost += 1
    if len(li) == 0:
        break

if n == 1:
  print(1)
else:
  print(cost)

Submission status: Wrong Answer

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

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        if xy[i][0]-xy[j][0]<0:
            list_.append((abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))
        else:
            list_.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))

if N==1:
    print(1)
else:
    print(N-Counter(list_).most_common()[0][1])

Submission status: Wrong Answer

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

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        if xy[i][0]-xy[j][0]<0:
            list_.append((abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))
        else:
            list_.append((abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))

if N==1:
    print(1)
else:
    print(N-Counter(list_).most_common()[0][1])

Submission status: Wrong Answer

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])
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
for j in range(n-1):
  for i in range(n-1):
    if a[i][0]>a[i+1][0]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
    elif a[i][0]==a[i+1][0]:
      if (a[i][1]-a[i+1][1])*p[1]>0:
        w=a[i]
        a[i]=a[i+1]
        a[i+1]=w
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: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
ball = [[int(i) for i in input().split()] for k in range(N)]
diff = []
if N == 1:
    print(1)
else:
    for i in range(N-1):
        for j in range(i+1, N):
            diff.append((ball[i][n]-ball[j][n] for n in range(2)))
    k = Counter(diff).most_common()[0][1]
    print(max(1,N-1-k))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

dicP = {}
dicQ = {}
for n1 in range(N):
	for n2 in range(N):
		if n1 == n2:
			continue
			
		p = xys[n1][0] - xys[n2][0]
		q = xys[n1][1] - xys[n2][1]
		
		if p == 0 or q == 0:
			continue
		
		#print(n1,n2,p,q)
		
		if p not in dicP:
			dicP[p] = 1
		else:
			dicP[p] += 1
		
		if q not in dicQ:
			dicQ[q] = 1
		else:
			dicQ[q] += 1
		

#print(dicP)
#print(dicQ)
	
maxPCount = 0
maxP = 0
for p,c in dicP.items():
	if maxPCount < c:
		maxPCount = c
		maxP = p
	
maxQCount = 0
maxQ = 0	
for q,c in dicQ.items():
	if maxQCount < c:
		maxQCount = c
		maxQ = q
		
print(N - min(maxPCount,maxQCount))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
h = defaultdict(int)
for x, y in xy:
    h[(x, y)] = True
mx, my = xy[-1]
ans = 10**10
for i in range(n-1):
    x1, y1 = xy[i]
    for j in range(i+1, n):
        x2, y2 = xy[i+1]
        z1 = x2-x1
        z2 = y2-y1

        t = set()
        k = 0
        a = 0
        while k < n and len(t) < n:
            xk, yk = xy[k]
            if (xk, yk) not in t:
                a += 1
                while xk <= mx and yk <= my:
                    if (xk, yk) in h:
                        t.add((xk, yk))
                    xk += z1
                    yk += z2
            k += 1
        if a < ans:
            ans = a

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import statistics
import math
from collections import Counter
N=int(input())
x=[]
y=[]
for a in range(N):
    b,c=(int(xxx) for xxx in input().split())
    x.append(b)
    y.append(c)
sa=deque([[0,0]])
if N>1:
    for a in range(N):
        for b in range(N-a-1):
            sx=abs(x[a]-x[a+b+1])
            sy=abs(y[a]-y[a+b+1])
            sa.append([sx,sy])
    sa.remove([0,0])
    ans=[]
    nagasa=len(sa)
    for a in range(nagasa):
        xx,yy=sa[a]
        ss=sa.count([xx,yy])
        ans.append(ss)
        if len(sa)==0:
            break
    kotae=max(ans)
    print(N-kotae)

else:
    print(1)

Submission status: Wrong Answer

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])
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
for j in range(n-1):
  for i in range(n-1):
    if a[i][0]>a[i+1][0]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
    elif a[i][0]==a[i+1][0]:
      if (a[i][1]-a[i+1][1])*p[1]<0:
        w=a[i]
        a[i]=a[i+1]
        a[i+1]=w
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)