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:
N = int(input())
X,Y = [],[]
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
inf = 10**10

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

Submission status: Wrong Answer

Solution code:
N=int(input())
x=[]
y=[]
if N==1:
    print(1)
for i in range(N):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
c=[]
for i in range(N):
    for j in range(i+1,N):
        c.append((x[i]-x[j],y[i]-y[j]))
        c.append((x[j]-x[i],y[j]-y[i]))
ans=100
for p,q in c:
    s=0
    for i in range(N):
        if (x[i]-p in x) and (y[i]-q in y):
            pass
        else:
            s+=1
    ans=min(ans,s)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
cst = 1
xy.sort(key = lambda x:x[0])
keep = xy[0]
mincst = float("inf")
if N != 1:
    for i in range(N-1):
        p = xy[i+1][0]-xy[i][0]
        q = xy[i+1][1]-xy[i][1]
        for i in range(1,N-1):
            if not(xy[i][0] == keep[0]+p and xy[i][1] == keep[1]+q):
                cst += 1
                keep = xy[i]
            else:
                keep = xy[i]
        if not(xy[N-1][0] == keep[0]+p and xy[N-1][1] == keep[1]+q):
            cst += 1
        if mincst > cst:
            mincst = cst
        cst = 1
else:
    print(1)
    exit()

print(mincst)

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

	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]))
	gess1 = {}
	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 gess1:
			gess1[(p, q)] += 1
		else:
			gess1[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess1, key=gess1.get)
	nai1 = gess1[(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]))
	xy = sorted(xy, key=lambda x:(x[1],-x[0]))
	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,nai1)

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from itertools import combinations as comb

N = int(input())
xy = []
xy_ap = xy.append

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

ls = [i for i in range(N)]

result = []


for i, j in comb(ls, 2):
    result.append([xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]])

cnt = 0
for i in range(len(result)):
    if result.count(result[i]) > cnt:
        cnt = result.count(result[i])

print(N - cnt)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alllist = []
minaslist = []

if N == 1:
    print("1")
else:
    for i in range(N):
        a,b = map(int,input().split())
        alllist.append([a,b])

    alllist.sort()

    for i in range(N-1):
        minaslist.append((alllist[i+1][0]-alllist[i][0] + 1)**2 - (alllist[i+1][1]-alllist[i][1] + 1)**3)



    countdict = collections.Counter(minaslist)

    lista = list(countdict.most_common())
    mostnum = lista[0][1]

    print(len(minaslist) - mostnum + 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
XY=[tuple(map(int,input().split())) for _ in range(n)]
XY.sort()
PQset=set()
for i in range(n):
    for j in range(i+1,n):
        p=abs(XY[j][0]-XY[i][0])
        q=abs(XY[j][1]-XY[i][1])
        if p!=0 or q!=0:
            PQset.add((p,q))
ans=n
for p,q in PQset:
    cost=1
    for i in range(1,n):
        x,y=XY[i]
        if (x-p,y-q) not in XY:
            cost+=1
    ans=min(cost,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort(key = lambda x: (-x[0], -x[1]))

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

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

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

Submission status: Wrong Answer

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

cost=n
ma=0

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

        for c in range(n-1):
            for d in range(c+1,n): 
                if x[c]==x[d]-p and y[c]==y[d]-q:
                    che=che+1
        ma=max(ma,che)

print(cost-ma)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
ary = []
d2 = []
max = 0
sin_max = 0
for _ in range(N):
    ball = list(map(int, input().split()))
    ary.append(ball)

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

for i in range(N):
    for j in range(N):
        x = ary[i][0] - ary[j][0]
        y = ary[i][1] - ary[j][1]
        tmp = str(x) + str(y)
        d2.append(tmp)
    max = d2.count(d2[0])
    for i in range(1,N):
        if max < d2.count(d2[i]):
            max = d2.count(d2[i])
    if sin_max < max:
        sin_max = max
    d2 = []
    max = 0

print(N - sin_max - 1)

Submission status: Wrong Answer

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

if len(AB_list) ==1:
    print(1)
    exit(0)

AB_list = sorted(AB_list,key=lambda a:a[0])
kouho_list = []
for i, AB in enumerate(AB_list):
    for j,ab in enumerate(AB_list[i+1:]):
        kouho_list.append((AB[0]-ab[0] ,AB[1]-ab[1]))

from collections import Counter
kouho_counter = Counter(kouho_list).most_common()
pq = list(kouho_counter[0][0])

onaji_list = []
#print(pq)

for i,ab in enumerate(AB_list):
    if i == 0:
        continue
    if pq[0] + ab[0] == AB_list[i-1][0] and pq[1] + ab[1] == AB_list[i-1][1]:
        onaji_list.append(ab)
        continue
    if pq[0] - ab[0] == AB_list[i-1][0] and pq[1] - ab[1] == AB_list[i-1][1]:
        onaji_list.append(ab)


#print(onaji_list)
print(len(AB_list)-len(onaji_list))





'''
候補は49 + 48 + 47 + ...
この候補の中で、一番えらばれているものをp,qとして設定する
その後、ループを回して、実際にコストを計算する

'''


#print(AB_list)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
pair_list = []
diff_list = {}
for _ in range(N):
  new_pair = np.array(list(map(int, input().split())))
  for pair in  pair_list:
    diff = tuple(pair - new_pair)
    if diff in diff_list:
      diff_list[diff] += 1
    else:
      diff_list[diff] = 1
  pair_list.append(new_pair)
if N > 1:
  print(N - min(max(diff_list.values()), N-1))
else:
  print(N)

Submission status: Wrong Answer

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

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

ans = float("inf")
for p in x_set:
    for q in y_set:
        cnt = 1
        for i in range(1, n):
            if (arr[i - 1][0], arr[i - 1][1]) != (arr[i][0] - p, arr[i][1] - q):
                cnt += 1
        ans = min(ans, cnt)
print(ans)

Submission status: 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)
    ans = inf
    for i in range(n):
        for k in range(n):
            if i != k:
                b = 1
                check = []
                check.append((i,k))
                p = xy[i][0] - xy[k][0]
                q = xy[i][1] - xy[k][1]
                for l in range(n):
                    for m in range(n):
                        if not((l,m) in check) and p == xy[l][0] - xy[m][0] and q == xy[l][1] - xy[m][1]:
                            b += 1
                            check.append((l, m))
                ans = min(ans, n-b)
    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:
N = int(input())
x_y = []
for i in range(N):
    x,y = map(int,input().split())
    x_y.append([x,y])

vectors = []
ans_inv = 0
for i in range(N):
    for j in range(i+1,N):
        vector = [x_y[i][0]-x_y[j][0],x_y[i][1]-x_y[j][1]]
#        print(vector)
        vector_inv = [x_y[j][0]-x_y[i][0],x_y[j][1]-x_y[i][1]]
        if not vector in vectors and not vector_inv in vectors:
            vectors.append(vector)
path = int(N*(N-1)/2) - len(vectors)
print(path)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
x = [0]*n
y = [0]*n
x_y_sum = [0]*n
total = []
p_q = []
for i in range(n):
    x[i], y[i] = map(int, input().split())
    x_y_sum[i] = x[i]+y[i]
    total.append([x_y_sum[i], x[i], y[i]])
total.sort()
cnt = 1
for i in range(1, n):
    p_q.append([total[i][1]-total[i-1][1], total[i][2]-total[i-1][2]])
p_q.sort()
new = []
for i in range(1, len(p_q)):
    new.append(list(set(p_q[i])-set(p_q[i-1])))
for i in range(len(new)):
    if new[i] != []:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import itertools

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

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

ptn=list(itertools.combinations(xy,2))
pq=[]
for idx,val in enumerate(ptn):
        if val[1][0]-val[0][0] < 0 and val[1][1]-val[0][1] < 0:
                pq.append(str(abs(val[1][0]-val[0][0])) + 'x' + str(abs(val[1][1]-val[0][1])))
        else:
                pq.append(str(val[1][0]-val[0][0]) + 'x' + str(val[1][1]-val[0][1]))

cpq = Counter(pq)

# pqans=cpq.most_common(1)[0][0]
redsc=cpq.most_common(1)[0][1]

# p,q = map(int,pqans.split('x'))
print(N-redsc)

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

Submission status: Wrong Answer

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

def gcd(a,b):
    a = abs(a)
    b = abs(b)
    while b:
        a,b = b,a%b
    return a

def make_PQ(a,b):
    if a>0:
        return(a//gcd(a,b),b//gcd(a,b))
    elif a<0:
        return(-1*a//gcd(a,b),-1*b//gcd(a,b))
    else:
        print("error")

if N <= 2:
    print(1)
else:
    PQ_list = []
    for i in range(1,N):
        for j in range(i):
            p = XY[j][0] - XY[i][0]
            q = XY[j][1] - XY[i][1]

            if p != 0:
                tmp_p,tmp_q = make_PQ(p,q)
                if not [tmp_p,tmp_q] in PQ_list:
                    PQ_list.append([tmp_p,tmp_q])
    tmp_set = set()
    for x,y in XY:
        tmp_set.add(x)
    ans = len(tmp_set)

    for p,q in PQ_list:
        XY_list = []
        for x1,y1 in XY:
            if XY_list == []:
                XY_list.append([x1,y1])
            else:
                for x2,y2 in XY_list:
                    if x2-x1 == 0:
                        break
                    else:
                        tmp_x,tmp_y = make_PQ(x2-x1,y2-y1)
                        if [tmp_x,tmp_y] == [p,q]:
                            break
                else:
                    XY_list.append([x1,y1])
        ans = min(ans,len(XY_list))

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

def gcd(x,y):
	if x<y:
		x,y = y,x
	if y == 0:
		return x
	return gcd(y,x%y)

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

main()

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
if N == 2:
    print(1)
    sys.exit()
ary = []
d2 = []
max = 0
sin_max = 0
for _ in range(N):
    ball = list(map(int, input().split()))
    ary.append(ball)


for i in range(N):
    for j in range(N):
        x = ary[i][0] - ary[j][0]
        y = ary[i][1] - ary[j][1]
        tmp = str(x) + str(y)
        d2.append(tmp)
    max = d2.count(d2[0])
    for i in range(1,N):
        if max < d2.count(d2[i]):
            max = d2.count(d2[i])
    if sin_max < max:
        sin_max = max
    d2 = []
    max = 0

print(N - sin_max - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
from operator import itemgetter

n = int(input())
if n == 1:
    print(1)
else:
    xy = []
    for i in range(n):
        xy_i = list(map(int, input().split()))
        xy.append(xy_i)

    st_xy1 = sorted(xy, key=itemgetter(0))
    st_xy = sorted(st_xy1, key=itemgetter(1))

    s = np.array(st_xy)

    L = list(map(list,np.diff(s.transpose()).transpose()))

    ans = []
    for LL in list(map(list, set(map(tuple, L)))):
        if LL[0] !=0 or LL[1] !=0:
            ans.append(L.count(LL))
    if len(ans) != 0:
        print(n - max(ans))
    else:
        print(n)

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

        group = []

        if p == 0 :
            for k in range(N) : # xがゼロ以下になるまで引き，切片を求める
                if ball[k][1] >= 0 :
                    mul = math.ceil(ball[k][1] / q)
                    b = ball[k][1] - q * mul
                else :
                    mul = math.ceil(-ball[k][1] / q) - 1
                    b = ball[k][1] + q * mul
                x = ball[k][0]
                group.append((x,b))
        else :
            for k in range(N) :
                if ball[k][0] >= 0 :
                    mul = math.ceil(ball[k][0] / p)
                    b = ball[k][1] - q * mul
                    x = ball[k][0] - p * mul
                else :
                    mul = math.ceil(-ball[k][0] / p) - 1
                    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:
n=int(input())
XY=[tuple(map(int,input().split())) for _ in range(n)]
XY.sort()
PQset=set()
for i in range(n):
    for j in range(i+1,n):
        p=abs(XY[j][0]-XY[i][0])
        q=abs(XY[j][1]-XY[i][1])
        if p!=0 or q!=0:
            PQset.add((p,q))
ans=float('inf')
for p,q in PQset:
    cost=1
    for i in range(1,n):
        x,y=XY[i]
        if (x-p,y-q) not in XY:
            cost+=1
    ans=min(cost,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#標準入力
N = int(input())
S = []
S = [list(map(int, input().split())) for i in range(N)]

ans = 1
i = 0
j = 0
for _ in range(N):
  try:
    a =(S[i+1][1]-S[i][1])/(S[i+1][0]-S[i][0])
    b = S[i][1]-a*S[i][0]
    for _ in range(N):
      if j > N-1:
        break
      if S[j][1]!=a*S[j][0]+b:
        ans+=1
        i = j
        j +=1
        break
      j +=1  
  except:
    for _ in range(N):
      if j > N-1:
        break
      if S[j][0]!=S[i][0]:
        ans+=1
        i = j
        j +=1
        break
      j+=1
print(ans)

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



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
x=[0]*n
y=[0]*n
X=[0]*(n-1)
Y=[0]*(n-1)
for i in range(n):
  x[i], y[i] = map(int,input().split())
x=sorted(x)
for i in range(n-1):
  X[i] = x[i+1] - x[i]
  Y[i] = y[i+1] - y[i]
XX=[i for i in X if i!=0]
YY=[i for i in Y if i!=0]
if XX==[] or YY==[]:
  print(n)
else:
  modex = collections.Counter(XX).most_common()[0][0]
  modey = collections.Counter(YY).most_common()[0][0]
  lx = X.count(modex)
  ly = Y.count(modey)
  print(n-min(lx,ly))

Submission status: Wrong Answer

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


for i in range(n):
    for j in range(i+1,n):
        l.append([p[j][0]-p[i][0],p[j][1]-p[i][1]])

m=0
for i in range(len(l)):
    cnt=0
    for j in range(len(l)):
        if l[i][0]==0:
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                cnt+=1
        elif l[i][1]==0:
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                cnt+=1
        elif l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                cnt+=1
        if cnt>m:
            m=cnt
        
ans=n
if m!=0:
    ans=n-m-1
if n==2:
    ans=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = list(map(int, input().split()))
d = {0:1}

pos=[]
for x in range(N[0]):
    a = list(map(int, input().split()))
    for y in pos:
        key = (a[0]-y[0])*(10**11)+(a[1]-y[1])
        if key<0:
            key=-key
        if key not in d.keys():
            d[key] = 0
        d[key] += 1
    pos.append(a)
    
print(N[0]-max(d.values()))

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

print(B)

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