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:
l = input().split()
N = int(l[0])

XY = []

for i in range(N):
    l = input().split()
    XY.append((int(l[0]), int(l[1])))

# print(N, XY)

# diffs = {}

# for i in range(N):
#     for j in range(N):
#         print(i, j)
#         if i == j:
#             continue
#         h = (X[i] - X[j], Y[i] - Y[j])
#         if h not in diffs:
#             diffs[h] = 0
#         diffs[h] += 1
#         h = (X[j] - X[i], Y[j] - Y[i])
#         if h not in diffs:
#             diffs[h] = 0
#         diffs[h] += 1

# print(diffs)

max_cost = 0
for i in range(N):
    cost_i = 0
    xy_i = XY[i]
    for j in range(N):
        cost = 1
        if i == j:
            continue
        xy_j = XY[j]
        diff_x = xy_i[0] - xy_j[0]
        diff_y = xy_i[1] - xy_j[1]
        # print(i, j, diff_x, diff_y)

        b_x = xy_j[0]
        b_y = xy_j[1]
        consumed = [i, j]
        while len(consumed) < N:
            found = False
            for k in range(N):
                if k in consumed:
                    continue
                d_x = b_x - XY[k][0]
                d_y = b_y - XY[k][1]
                if d_x == diff_x and d_y == diff_y:
                    cost += 1
                    b_x = XY[k][0]
                    b_y = XY[k][1]
                    consumed.append(k)
                    found = True
            if not found:
                break

        for k in range(N):
            if k == i or k == j:
                continue
            for l in range(N):
                if l == i or l == j:
                    continue
                d_x = XY[k][0] - XY[l][0]
                d_y = XY[k][1] - XY[l][1]
                if d_x == diff_x and d_y == diff_y:
                    cost += 1
        # print('cost', cost)
        cost_i = max(cost_i, cost)
    # print('cost_i', cost_i)
    max_cost = max(max_cost, cost_i)

print(N - max_cost)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ball = [0] * N

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

ans = N

# p,q の組
for i in range(N) :
    for j in range(N) :
        p = ball[j][0] - ball[i][0]
        q = ball[j][1] - ball[i][1]

        if p == 0 and q == 0 :
            continue

        if q < 0 : # qを正にする
            q *= -1
            p *= -1

        group = []

        if p == 0 :
            for k in range(N) : # xがゼロ以下になるまで引き，切片を求める
                if ball[k][1] >= 0 :
                    mul = math.ceil(ball[k][1] / q)
                else :
                    mul = math.floor(ball[k][1] / q)
                b = ball[k][1] - q * mul
                x = ball[k][0]
                group.append((x,b))
        else :
            for k in range(N) :
                mul = math.ceil(ball[k][0] / p) # 引く回数
                if ball[k][0] >= 0 :
                    mul = math.ceil(ball[k][0] / p)
                else :
                    mul = math.floor(ball[k][0] / p)
                b = ball[k][1] - q * mul
                x = ball[k][0] - p * mul
                group.append((x,b))
        count = set(group)
        ans = min(ans,len(count))

print(ans)

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###
import collections

N = int(input())
XYs = [tuple(mi()) for _ in range(N)]

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

sa_list = []
import itertools
for (ax, ay), (bx, by) in itertools.combinations(XYs, 2):
  sa_list.append((ax-bx,ay-by) if ax-bx>=0 else (-(ax-bx),-(ay-by)))

#最も多い差の個数（これ-1を短縮できるはず）
#print(N-collections.Counter(sa_list).most_common()[0][1])

#最も多い差をタプルで受ける
mostcommon = collections.Counter(sa_list).most_common()[0][0]
#print(mostcommon)


#print(sa_list)
cnt = 0
ans = N #ここから引いていく
#aとbの差がmostcommonと一致したらvisitedに入れる
visited = [0] * N
for a in range(0, N):
  tmpsame = 0 #今見ているaと差が同じものの数
  for b in range(0, N):
    if a>=b or visited[b]: continue
    sa = sa_list[cnt]
    if sa == mostcommon:
#      print('same')
      ans -= 1
      visited[a] = 1
      visited[b] = 1
    cnt += 1
#    print(sa)

if len(sa_list)>=2:
  #次に多い差をタプルで受ける
  mostcommon = collections.Counter(sa_list).most_common()[1][0]
  cnt = 0
  ans2 = N #ここから引いていく
  #aとbの差がmostcommonと一致したらvisitedに入れる
  visited2 = [0] * N
  for a in range(0, N):
    tmpsame = 0 #今見ているaと差が同じものの数
    for b in range(0, N):
      if a>=b or visited2[b]: continue
      sa = sa_list[cnt]
      if sa == mostcommon:
        ans2 -= 1
        visited[a] = 1
        visited2[b] = 1
      cnt += 1
  print(min(ans, ans2))
else:
  print(ans)

Submission status: Wrong Answer

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

cost_min = 10 ** 4
if N == 1 or N == 2:
  print(1)
else:
  xy.sort()
  for i in range(N-1):
    cost = 1
    p = xy[i][0] - xy[i+1][0]
    q = xy[i][1] - xy[i+1][1]
    for j in range(N-1):
      if xy[j+1][0] + p == xy[j][0] and xy[j+1][1] + q == xy[j][1]:
        pass
      else:
        cost += 1
    if cost < cost_min:
      cost_min = cost
  xy = sorted(xy, key=lambda x: x[1])
  for i in range(N-1):
    cost = 1
    p = xy[i][0] - xy[i+1][0]
    q = xy[i][1] - xy[i+1][1]
    for j in range(N-1):
      if xy[j+1][0] + p == xy[j][0] and xy[j+1][1] + q == xy[j][1]:
        pass
      else:
        cost += 1
    if cost < cost_min:
      cost_min = cost
  if N > 3:
    for i in range(N-2):
      cost = 1
      p = xy[i][0] - xy[i+2][0]
      q = xy[i][1] - xy[i+2][1]
      for j in range(N-2):
        if xy[j+2][0] + p == xy[j][0] and xy[j+2][1] + q == xy[j][1]:
          pass
        else:
          cost += 1
      for j in range(1, N-2, 2):
        cost += 1
        if xy[j+2][0] + p == xy[j][0] and xy[j+2][1] + q == xy[j][1]:
          pass
        else:
          cost += 1
      if cost < cost_min:
        cost_min = cost
    xy.sort()
    for i in range(N-2):
      cost = 1
      p = xy[i][0] - xy[i+2][0]
      q = xy[i][1] - xy[i+2][1]
      for j in range(N-2, 2):
        if xy[j+2][0] + p == xy[j][0] and xy[j+2][1] + q == xy[j][1]:
          pass
        else:
          cost += 1
      for j in range(1, N-2, 2):
        cost += 1
        if xy[j+2][0] + p == xy[j][0] and xy[j+2][1] + q == xy[j][1]:
          pass
        else:
          cost += 1
      if cost < cost_min:
        cost_min = cost
  
      
  print(cost_min)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import combinations

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

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

        p = x2 - x1
        q = y2 - y1

        cnt1 = 0
        cnt2 = 0

        if p == q == 0:
            continue

        for x, y in cord:
            if (x - p, y - q) not in cord:
                cnt1 += 1

            if (x + p, y + q) not in cord:
                cnt2 += 1

        ans = min(ans, cnt1, cnt2)

    return ans


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

Submission status: Wrong Answer

Solution code:
# 2019 6/15
# diverta 2019 B Picking Up

import sys

ball = []


def cal_cost(li, p, q, cost):
    if (li[i][0] == li[i-1][0] - p) and (li[i][1] == li[i-1][1] - q):
        return cost
    else:
        cost += 1
        return cost


def total_cost(li, p, q, cost):
    for i in range(1, len(li)):
        cost = cal_cost(li, p, q, cost)
    return cost


def cal_grad(li):
    count = 0
    count_x = 0
    count_y = 0
    for k in range(1, len(li)):
        for i in range(1, len(li)):
            if i + k >= len(li):
                continue
            a = li[i + k][0] - li[i-1][0]
            b = li[i + k][1] - li[i-1][1]
            if a == 0 or b == 0:
                continue
                # tmp = -2
                # for j in range(len(li)):
                #     if li[j][0] == 0:
                #         tmp += 1
                #         count = tmp
                #         count_x = 0
                #         count_y = b
            for j in range(len(li)):
                if j != i and j != i-1:
                    tmp = 0
                    if li[j][0] % a == li[i][0] % a and li[j][1] % b == li[i][1] % b:
                        tmp += 1
                    if count < tmp:
                        count = tmp
                        count_x = a
                        count_y = b
    return count_x, count_y


if __name__ == '__main__':
    N = int(input())
    for i in range(N):
        ball.append(list(map(int, input().split())))

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

    p, q = cal_grad(ball)

    cost = total_cost(ball, p, q, 1)
    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())
for j in range(N-1):
    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.full(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 q in range(N):
            for r in range(q):
                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(ans_min)))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
xy = []
for _ in range(n):
    xy.append(list(map(int, input().split())))

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

xy.sort(key=itemgetter(1))
xy.sort(key=itemgetter(0))

diff = []
for tmp in range(n-1):
    diff.append(
        [xy[tmp][0] - xy[tmp+1][0], xy[tmp][1] - xy[tmp+1][1]]
        )

ans = get_unique_list(diff)


print(len(ans))

Submission status: Wrong Answer

Solution code:
import statistics
import copy
import collections
n=int(input())
if n==1:
    x=list(map(int,input().split()))
    print(1)
else:
    x=[0]*n
    xx=[0]*(n-1)
    yy=[0]*(n-1)
    for i in range(n):
        x[i]=list(map(int,input().split()))
    x.sort(key=lambda x:x[1])
    x.sort(key=lambda x:x[0])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=collections.Counter(xx).most_common()[0][0]
    Y=collections.Counter(yy).most_common()[0][0]
    if X==0 and Y==0:
        XX=copy.copy(xx)
        XX.remove(0)
        X=collections.Counter(xx).most_common()[0][0]
        YY=copy.copy(yy)
        YY.remove(0)
        Y=collections.Counter(yy).most_common()[0][0]
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        cntx0=n-1-xx.count(0)+1
        cnty0=n-1-yy.count(0)+1
        ansxmin(max(cntx0,cnty),max(cntx,cnty0))
    else:
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        ansx=max(cntx,cnty)
    x.sort(key=lambda x:x[0])
    x.sort(key=lambda x:x[1])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=collections.Counter(xx).most_common()[0][0]
    Y=collections.Counter(yy).most_common()[0][0]
    if X==0 and Y==0:
        XX=copy.copy(xx)
        XX.remove(0)
        X=collections.Counter(xx).most_common()[0][0]
        YY=copy.copy(yy)
        YY.remove(0)
        Y=collections.Counter(yy).most_common()[0][0]
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        cntx0=n-1-xx.count(0)+1
        cnty0=n-1-yy.count(0)+1
        ansy=min(max(cntx0,cnty),max(cntx,cnty0))
    else:
        cntx=n-1-xx.count(X)+1
        cnty=n-1-yy.count(Y)+1
        ansy=max(cntx,cnty)
    print(min(ansx,ansy))

Submission status: Wrong Answer

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

def f(_pts, p, q):
    pts = set(_pts[:])
    r = 0

    while len(pts) > 0:
        r += 1
        x = max(pts)
        while x in pts:
            pts.remove(x)
            x = (x[0]-p, x[1]-q)

    return r

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

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, abs(pts[i][0]-pts[j][0]), abs(pts[i][1]-pts[j][1]))
        res = min(res, l)

print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 1:
    print(2)
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:
from collections import deque
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
cost = float('Inf')
for st in xy:
    for nx in xy:
        if st != nx:
            p = nx[0] - st[0]
            q = nx[1] - st[1]
        else:
            continue
        que = deque()
        que.append(st)
        for t in xy:
            if t != st:
                que.append(t)
        tmp = 0
        flag = True
        while len(que) > 0:
            if flag:
                st2 = que.popleft()
                tmp += 1
            flag = True
            nque = deque()
            for nx2 in que:
                if (nx2[0] - st2[0]) == p and (nx2[1] - st2[1]) == q:
                    st2 = nx2
                    flag = False
                else:
                    nque.append(nx2)
            que = nque
        if tmp < cost:
            cost = tmp
print(cost)

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 = sorted(xy, key=lambda x:(x[0]))
	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]))
	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]))
	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)]

	#########
	xy = sorted(xy, key=lambda x:(x[0],-x[1]))
	gess5 = {}
	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 gess5:
			gess5[(p, q)] += 1
		else:
			gess5[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess5, key=gess5.get)
	nai5 = gess5[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(-x[0],-x[1]))
	gess6 = {}
	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 gess6:
			gess6[(p, q)] += 1
		else:
			gess6[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess6, key=gess6.get)
	nai6 = gess6[(p,q)]

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

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

ret = 0
pq = []

for i in range(N) :        
    for j in range(i+1, N) :
        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]
        if p != 0 and q != 0 :
            pq.append((p, q))
        
pq = list(set(pq))

ret = float('inf')
for p, q in pq :
    print(p, q)
    tmp = 0
    visited = [0] * N
    for i in range(N) :
        if visited[i] :
            continue
            
        for j in range(N) :
            if visited[j] :
                continue
            dx = xy[j][0] - xy[i][0]
            dy = xy[j][1] - xy[i][1]
            if dx % p == 0 and dy % q == 0 and dx // p == dy // q:
                visited[j] = 1
                    
        tmp += 1
    print(tmp)
    ret = min(tmp, ret)
    
print(ret)

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###
import collections

N = int(input())
XYs = [tuple(mi()) for _ in range(N)]

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

sa_list = []
import itertools
for (ax, ay), (bx, by) in itertools.combinations(XYs, 2):
  sa_list.append((ax-bx,ay-by) if ax-bx>=0 else (-(ax-bx),-(ay-by)))

#最も多い差の個数（これ-1を短縮できるはず）
#print(N-collections.Counter(sa_list).most_common()[0][1])

#最も多い差をタプルで受ける
mostcommon = collections.Counter(sa_list).most_common()[0][0]
#print(mostcommon)


#print(sa_list)
cnt = 0
ans = N #ここから引いていく
#aとbの差がmostcommonと一致したらvisitedに入れる
visited = [0] * N
for a in range(0, N):
  tmpsame = 0 #今見ているaと差が同じものの数
  for b in range(0, N):
    if a>=b or visited[b]: continue
    sa = sa_list[cnt]
    if sa == mostcommon:
#      print('same')
      ans -= 1
      visited[b] = 1
    cnt += 1
#    print(sa)

if len(sa_list)>=2:
  #次に多い差をタプルで受ける
  mostcommon = collections.Counter(sa_list).most_common()[1][0]
  cnt = 0
  ans2 = N #ここから引いていく
  #aとbの差がmostcommonと一致したらvisitedに入れる
  visited2 = [0] * N
  for a in range(0, N):
    tmpsame = 0 #今見ているaと差が同じものの数
    for b in range(0, N):
      if a>=b or visited2[b]: continue
      sa = sa_list[cnt]
      if sa == mostcommon:
        ans2 -= 1
        visited2[b] = 1
      cnt += 1
  print(min(ans, ans2))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    points = []
    for i in inputs:
        points.append(string_to_int(i))
    N = len(points)

    # if N == 1 or N == 2:
    #     return 1

    min = None

    for i, _ in enumerate(points):
        for j in range(i + 1, N):
            try_p = points[i][0] - points[j][0]
            try_q = points[i][1] - points[j][1]

            a = try_q / try_p if try_p != 0 else 0

            bs = {}
            hits = {x: None for x in range(0, N)}
            for try_i, _ in enumerate(points):
                for try_j in range(try_i + 1, N):
                    diff_x = points[try_j][0] - points[try_i][0]
                    diff_y = points[try_j][1] - points[try_i][1]

                    check_a = diff_y / diff_x if diff_x != 0 else 0
                    if abs(a) != abs(check_a):
                        continue

                    check_b = (
                        (points[try_j][1] + points[try_i][1])
                        - check_a * (points[try_j][0] + points[try_i][0])
                    ) / 2

                    if check_b not in bs:
                        bs[check_b] = True

                    hits[try_i] = True
                    hits[try_j] = True
            count = len(bs)
            for value in hits.values():
                if value is None:
                    count += 1
            if min is None or min > count:
                min = count
    return min


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N] = string_to_int(input())
    ret = solve(inputs(N))
    print(ret)

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 = sorted(xy, key=lambda x:(x[0]))
	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]))
	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]))
	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)]

	#########
	xy = sorted(xy, key=lambda x:(x[0],-x[1]))
	gess5 = {}
	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 gess5:
			gess5[(p, q)] += 1
		else:
			gess5[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess5, key=gess5.get)
	nai5 = gess5[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(-x[0],x[1]))
	gess6 = {}
	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 gess6:
			gess6[(p, q)] += 1
		else:
			gess6[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess6, key=gess6.get)
	nai6 = gess6[(p,q)]

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

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
if n==1:
  print(1)
else:
  ans=[]
  for i in range(n):
    x1=l[i][0]
    y1=l[i][1]
    for j in range(n):
      if i!=j:
        x2=l[j][0]
        y2=l[j][1]
        if (x1-x2)!=0:
          p=(y1-y2)/(x1-x2)
          L=[]
          for k in range(n):
            L.append(round(l[k][1]-l[k][0]*p,8))
          ans.append(len(set(L)))
        else:
          L=[]
          for k in range(n):
            L.append(l[k][0])
          ans.append(len(set(L)))
  print(min(ans))

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    XY = LLIN(N)
    if N == 1:
        print(1)
        exit()
    ans = inf
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            p = XY[i][0] - XY[j][0]
            q = XY[i][1] - XY[j][1]
            pre_exist = set()
            pre_exist.add((XY[i][0], XY[i][1]))
            mini_ans = 1
            for (x, y) in XY:
                found = False
                #print((x,y),pre_exist,mini_ans)
                for (px, py) in pre_exist.copy():
                    if (x, y) == (px, py):
                        found = True
                        continue
                    dx = px - x
                    dy = py - y
                    #print(dx,dy,p,q)
                    if abs(dx) == abs(p) and abs(dy) == abs(q):
                        found = True
                        break
                if not found:
                    pre_exist.add((x,y))
                    mini_ans += 1
                        
            #print(pre_exist,mini_ans)
            ans = min(ans, mini_ans)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = []

def xy_count(diff_XY,xy):
  count = 0
  for i in range(len(diff_XY)):
    if xy in diff_XY[i]:
      count += 1
  return count

for i in range(N):
  XY.append(list([int(i) for i in input().split()]))

diff_XY = [[[0] * 2 for i in range(N)] for i in range(N)]
search_XY = []
ans = N

for i in range(N):
  for j in range(i+1,N):
    tmp = [XY[i][0]-XY[j][0],XY[i][1]-XY[j][1]]
    diff_XY[i][j] = tmp
    if tmp not in search_XY:
      search_XY.append(tmp)

ans_diff = 1
for xy in search_XY:
  ans_diff = max(ans_diff, xy_count(diff_XY,xy))

print(ans-ans_diff)