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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    a = n - k
    if k == 1:
        print(0)
        return
    print(a)
    return

#B
def B():
    n = II()
    xy = LIR(n)
    pa = itertools.permutations(range(n), n)
    ans = inf
    for p in pa:
        anslis = []
        for i in range(n-1):
            x1, y1 = xy[p[i]]
            x2, y2 = xy[p[i + 1]]
            anslis.append((x1 - x2, y1 - y2))
        anslis = set(anslis)
        ans = min(len(anslis), ans)
    print(ans)

    return

#C
def C():
    m = II()
    a = LI()
    a.sort()
    check = [0] * m
    anslis = []
    ans = 0
    if m % 2:
        ans += a[m // 2]
        for i in range(m//2):
            anslis.append((a[i], a[-1 - i]))
            anslis.append((ans,-a[-1 - i]+a[i]))
            ans += a[-1 - i] - a[i]
    else:
        ans += a[m//2] - a[m//2-1]
        for i in range(m//2-1):
            anslis.append((a[i], a[-1 - i]))
            anslis.append((ans,-a[-1 - i]+a[i]))
            ans += a[-1 - i] - a[i]
    print(ans)
    for a, b in anslis:
        print(a,b)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from itertools import combinations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")
for (x1, y1), (x2, y2) in combinations(XY, 2):
    p, q = (x2-x1), (y2-y1)
    XY_ = deepcopy(XY)

    #XY_.sort()
    XY_.sort(key=lambda v: (v[0]*q - v[1]*p, v[0], v[1]))
    an = 0
    xp, yp = float("inf"), float("inf")
    for x, y in XY_:
        if xp+p==x and yp+q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    # if ans > an:
    #     print(p, q)
    ans = min(ans, an)
    for x, y in XY_:
        if xp-p==x and yp-q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    #if ans > an:

    ans = min(ans, an)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 1:
    print(1)
else:
    xys = [[int(j) for j in input().split()] for i in range(N)]
    xys.sort(key=lambda x: x[0])
    hikizan = [[xy2[0] - xy1[0], xy2[1] - xy1[1]] for i, xy1 in enumerate(xys) for j, xy2 in enumerate(xys) if i < j]
    counting = [sum([1 for c in hikizan if h[0]==c[0] and h[1]==c[1]]) for h in hikizan]
    print(N - max(counting))

Submission status: Wrong Answer

Solution code:
x = []
y = []

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

if N == 1:
    print(1)
    exit()
    
p = []
q = []

for i in range(1, N):
    p.append(x[i]-x[0])
    q.append(y[i]-y[0])

#print(p, q, len(p))


count_min = 1
for kouho in range(len(p)):
    count = 1
    
    for i in range(1, N):
        if (x[i] != (x[i-1] + p[kouho])) or (y[i] != (y[i-1] + q[kouho])):
            count += 1
            
    if count_min > count:
        count_min = count
        
print(count_min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import combinations

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

    ans = 50
    for a in combinations(cord, 2):
        x1, y1 = a[0]
        x2, y2 = a[1]

        if x1 == x2:
            cnt = set()
            for x, y in cord:
                cnt.add(x)

            ans = min(ans, len(cnt))

        elif y1 == y2:
            cnt = set()
            for x, y in cord:
                cnt.add(y)
            
            ans = min(ans, len(cnt))

        else:
            p = x2 - x1
            q = y2 - y1

            b = set()
            for x, y  in cord:
                b.add(y * p  - q  * x)

            ans = min(ans, len(b))

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:

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

for i in range(N):
    for k in range(N):
        if i < k:
            if XYi[i][0] > XYi[k][0]:
                t = XYi[i]
                XYi[i] = XYi[k]
                XYi[k] = t
            elif XYi[i][0] == XYi[k][0]:
                if XYi[i][1] > XYi[k][1]:
                    t = XYi[i]
                    XYi[i] = XYi[k]
                    XYi[k] = t

dictX = {}
dictY = {}
for i in range(N - 1):
    x, y = XYi[i][0], XYi[i][1]
    nx, ny = XYi[i + 1][0], XYi[i + 1][1]
    tx = x - nx
    ty = y - ny

    vx = dictX.get(tx)
    vy = dictY.get(ty)

    if vx:
        dictX[tx] = vx + 1
    else:
        dictX[tx] = 1
    if vy:
        dictY[ty] = vy + 1
    else:
        dictY[ty] = 1

p = 0
q = 0
maxv = 0
for i in dictX.keys():
    v = dictX[i]
    if v > maxv:
        maxv = v
        p = i

maxv = 0
for i in dictY.keys():
    v = dictY[i]
    if v > maxv:
        maxv = v
        q = i

cost = 1
for i in range(N - 1):
    x, y = XYi[i][0], XYi[i][1]
    nx, ny = XYi[i + 1][0], XYi[i + 1][1]
    tx = x - nx
    ty = y - ny
    if tx == p and ty == q:
        pass
    else:
        cost += 1
print(cost)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
xy = sorted([list(map(int, input().split())) for _ in range(N)])
xlist = []
for i in range(1, len(xy)):
    x = xy[i-1][0]-xy[i][0]
    y = xy[i-1][1]-xy[i][1]
    if x < 0 and y < 0:
        x *= -1
        y *= -1
    xlist.append((x,y))

c = Counter(xlist)
m = 0
for (x, y) in c:
    m = max(m, c[(x, y)])
print(N-m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def get_2dline(p1, p2):
    return p2[0] - p1[0], p1[1] - p2[1]


def main():
    n = int(input())
    points = []
    for _ in range(n):
        points.append(tuple(map(int, input().split())))

    lines = set()
    for i in range(n):
        for j in range(n):
            a, b = get_2dline(points[i], points[j])
            lines.add((a, b))
    lines.discard((0, 0))

    res = n
    for p, q in lines:
        counter = set()
        for x, y in points:
            counter.add(p * x + q * y)
        res = min(res, len(counter))
    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from itertools import combinations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")
for (x1, y1), (x2, y2) in combinations(XY, 2):
    p, q = (x2-x1), (y2-y1)
    XY_ = deepcopy(XY)

    XY_.sort()
    XY_.sort(key=lambda v: (v[0]*q - v[1]*p))
    an = 0
    xp, yp = float("inf"), float("inf")
    for x, y in XY_:
        if xp+p==x and yp+q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    # if ans > an:
    #     print(p, q)
    ans = min(ans, an)
    for x, y in XY_:
        if xp-p==x and yp-q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    #if ans > an:

    ans = min(ans, an)
print(ans)

Submission status: Wrong Answer

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

def f(pts, p, q):
    c = []
    for pt in pts:
        c.append(q*pt[0]-p*pt[1])

    return len(set(c))

################################################################################

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

res = n
for i in range(len(pts)):
    for j in range(i+1, len(pts)):
        l = f(pts, pts[i][0]-pts[j][0], pts[i][1]-pts[j][1])
        res = min(res, l)

print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, x: "List[int]", y: "List[int]"):
    # rted(a, key=lambda x:x[1], reverse=True)

    a = [[x[i],y[i]] for i in range(N)]
    a = sorted(a, key=lambda x:x[0])

    x.sort()
    y.sort()

    sx = [x[i+1]-x[i] for i in range(N-1)]
    sy = [y[i+1]-y[i] for i in range(N-1)]

    from collections import Counter

    csx = Counter(sx)
    csy = Counter(sy)

    # p = csx.most_common()[0][0]
    p = [i for i,v in csx.most_common()]
    pm = [-1*i for i in p]
    # print(p)
    # q = csy.most_common()[0][0]
    q = [i for i,v in csy.most_common()]
    qm = [-1*i for i in q]
    p = p + pm
    q = q + qm
    p.sort()
    q.sort()
    p = set(p)
    q = set(q)
    # print(p)

    ans = 10000000000
    for i in p:
        for j in q:
            tans = 1
            for k in range(1,N):
                s,t = a[k]
                if(a[k-1][0] == s+i and a[k-1][1] == t+j):
                    continue
                else:
                    tans += 1
            ans = min(ans,tans)


    print(ans)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

for i in range(N):
    for k in range(N):
        if i < k:
            if XYi[i][0] > XYi[k][0]:
                t = XYi[i]
                XYi[i] = XYi[k]
                XYi[k] = t
            elif XYi[i][0] == XYi[k][0]:
                if XYi[i][1] > XYi[k][1]:
                    t = XYi[i]
                    XYi[i] = XYi[k]
                    XYi[k] = t

print(XYi)

dictX = {}
dictY = {}
for i in range(N - 1):
    x, y = XYi[i][0], XYi[i][1]
    nx, ny = XYi[i + 1][0], XYi[i + 1][1]
    tx = x - nx
    ty = y - ny

    vx = dictX.get(tx)
    vy = dictY.get(ty)

    if vx:
        dictX[tx] = vx + 1
    else:
        dictX[tx] = 1
    if vy:
        dictY[ty] = vy + 1
    else:
        dictY[ty] = 1

p = 0
q = 0
maxv = 0
for i in dictX.keys():
    v = dictX[i]
    if v > maxv:
        maxv = v
        p = i

maxv = 0
for i in dictY.keys():
    v = dictY[i]
    if v > maxv:
        maxv = v
        q = i

cost = 1
for i in range(N - 1):
    x, y = XYi[i][0], XYi[i][1]
    nx, ny = XYi[i + 1][0], XYi[i + 1][1]
    tx = x - nx
    ty = y - ny
    if tx == p and ty == q:
        pass
    else:
        cost += 1
print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = list(list(map(int,input().split()))+[0]for i in range(N))
xy=sorted(xy,reverse = True)
ans = 100
hoge = 0
p,q = 0,0

def func(n):
    xy[n][2] = 1
    if [xy[n][0]+p,xy[n][1]+q,0] in xy:
        func(xy.index([xy[n][0]+p,xy[n][1]+q,0]))


for i in range(N):
    for j in range(i+1,N):
        p,q = xy[j][0]-xy[i][0],xy[j][1]-xy[i][1] # p,qのあり得るパターン
        for k in range(N):
            if xy[k][2] == 0:
                func(k)
                hoge += 1
        ans = min(hoge,ans)
        hoge = 0
        for k in range(N):
            xy[k][2] = 0
print(ans)

Submission status: Wrong Answer

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

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

n = readi()
a = []
b = []
if n == 1:
    print(1)
    exit()
for i in range(n):
    x, y = readmi()
    a.append([x,y])
    b.append([y,x])
a.sort()
b.sort()
aa = defaultdict(int)
bb = defaultdict(int)
cc = defaultdict(int)
dd = defaultdict(int)
old1 = 0
old2 = 0
flg = True
for i in range(n - 1):
    aa[(a[i + 1][0] - a[i][0], a[i + 1][1] - a[i][1])] += 1
    bb[(b[i + 1][0] - b[i][0], b[i + 1][1] - b[i][1])] += 1
    cc[(a[i + 1][0] + a[i][0], a[i + 1][1] + a[i][1])] += 1
    dd[(b[i + 1][0] + b[i][0], b[i + 1][1] + b[i][1])] += 1
aaa = sorted(aa.items(), key=lambda x:x[1], reverse=True)
bbb = sorted(bb.items(), key=lambda x:x[1], reverse=True)
ccc = sorted(cc.items(), key=lambda x:x[1], reverse=True)
ddd = sorted(dd.items(), key=lambda x:x[1], reverse=True)
print(n - max(aaa[0][1],bbb[0][1],ccc[0][1],ddd[0][1]))

Submission status: Wrong Answer

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

if N<=2:
    print(1)
    exit()


def calc(p,q):
    result = set()
    if p == 0:
        for x,y in XY:
            result.add(x)
        return len(result)
    for x,y in XY:
        result.add(Fraction(y*p - (x * q),p))

    # print(p,q,result)
    return len(result)

ans = 5000

for i in range(N-1):
    for j in range(i,N):
        p = XY[i][0] - XY[j][0]
        q = XY[i][1] - XY[j][1]
        ans = min(ans,calc(p,q))

if ans == 5000:
    raise ValueError
print(ans)

Submission status: Wrong Answer

Solution code:
import math


def main():
    N = int(input())
    XY = [
        [int(a) for a in input().split()]
        for a in range(N)
    ]

    r = len(set(x for x, y in XY))
    for i in range(N):
        xy1 = XY[i]
        for j in range(i + 1, N):
            xy2 = XY[j]
            dx = xy1[0] - xy2[0]
            dy = xy1[1] - xy2[1]

            bs = set()
            if dx != 0:
                if dx < 0:
                    dx = -dx
                    dy = -dy

                for x, y in XY:
                    k = math.ceil(-x / dx)
                    while True:
                        if x + k * dx < 0:
                            k += 1
                        elif x + (k - 1) * dx >= 0:
                            k -= 1
                        else:
                            break

                    # while not x + k * dx>=0:

                    t = x + k * dx, y + k * dy
                    bs.add(t)
                # print(bs)
                r = min(len(bs), r)
            else:
                for x, y in XY:
                    bs.add(y)
                r = min(len(bs), r)

    print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

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

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

def main():

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 1:
    print(1)
else:
    xys = [[int(j) for j in input().split()] for i in range(N)]
    xys.sort(key=lambda x: x[0])
    print(xys)
    hikizan = [[xy2[0] - xy1[0], xy2[1] - xy1[1]] for i, xy1 in enumerate(xys) for j, xy2 in enumerate(xys) if i < j]
    counting = [sum([1 for c in hikizan if h[0]==c[0] and h[1]==c[1]]) for h in hikizan]
    print(N - max(counting))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

from itertools import combinations
from collections import Counter

def main():
  n = int(input())
  x = []
  y = []

  if n == 1:
    print(1)
    return

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

  cnt = Counter()

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

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

if __name__ == '__main__':
  main()