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())
xy = []
for i in range(N):
    tmpx, tmpy = map(int, input().split())
    xy.append([tmpx, tmpy])
xy.sort()

sub = []
for i in range(1, N):
    subx = xy[i][0] - xy[i-1][0]
    suby = xy[i][1] - xy[i-1][1]
    sub.append([subx, suby])

tmpli = []
count = []
for i in range(len(sub)):
    if sub[i] not in tmpli:
        tmpli.append(sub[i])
        cnt = sub.count(sub[i])
        count.append(cnt)

count.sort(reverse=True)
ans = 0
for i in range(1, len(count)):
    ans += count[i]

xy2 = sorted(xy, key=lambda x:x[1])

sub = []
for i in range(1, N):
    subx = xy2[i][0] - xy2[i-1][0]
    suby = xy2[i][1] - xy2[i-1][1]
    sub.append([subx, suby])

tmpli = []
count = []
for i in range(len(sub)):
    if sub[i] not in tmpli:
        tmpli.append(sub[i])
        cnt = sub.count(sub[i])
        count.append(cnt)

count.sort(reverse=True)
ans2 = 0
for i in range(1, len(count)):
    ans2 += count[i]

print(min(ans,ans2)+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))
X.sort(key=lambda x: x[0])
q1 = 0
max = 1
for i in range(N):
    for j in range(i, N):
        p = X[j][0] - X[i][0]
        t = 1
        for k in range(j, N):
            check = 1
            lis = [i, j]
            if (X[k][0] == X[j][0] * t):
                t += 1
                lis.append(k)
        if t > 1:
            for i in range(len(lis) - 1):
                q2 = q1
                q1 = X[lis[i + 1]][1] - X[lis[i]][1]
                if i > 1:
                    if q1 != q2:
                        break
                    else:
                        check += 1
        if check > max:
            max = check
print(N - max)

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 and LL[1] !=0:
            ans.append(L.count(LL))
    print(n - max(ans))

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][0]-xy[i-1][0]
    y = xy[i][1]-xy[i-1][1]
    xlist.append((x,y))

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

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]
    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]
    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 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])**2 - (alllist[i+1][1]-alllist[i][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 = sorted([list(map(int, input().split())) for _ in range(n)])
if n==1:
  print(1)
else:
  def cal(xy):
    dis = [0] * (n-1)
    a,b = xy[0]
    for idx,(x,y) in enumerate(xy[1:]):
      dis[idx] = (x-a,y-b)
      a,b = x,y
    
    return n - max([dis.count(tuple(i)) for i in set(dis)])
  
  print(min(cal(xy),cal(sorted(xy,key=lambda x:x[1]))))

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 = max(1, min(ans, cnt1, cnt2))

    return ans


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

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)



if __name__ == "__main__":
	main()

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, -(pts[i][0]-pts[j][0]), -(pts[i][1]-pts[j][1]))
        l = f(pts, +(pts[i][0]-pts[j][0]), -(pts[i][1]-pts[j][1]))
        l = f(pts, -(pts[i][0]-pts[j][0]), +(pts[i][1]-pts[j][1]))
        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:
import collections
import itertools

N = int(input())

x, y = [], []

for i in range(N):
    xx, yy = list(map(int, input().split()))
    x.append(xx)
    y.append(yy)

l = []

if N == 1 or N == 2:
    print(1)
else:
    for c in itertools.combinations(range(N), 2):
        x1 = x[c[0]]
        y1 = y[c[0]]
        x2 = x[c[1]]
        y2 = y[c[1]]

        if x1 - x2 < 0:
            xtmp, ytmp = x2, y2
            x2, y2 = x1, y1
            x1, y1 = xtmp, ytmp

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

    c = collections.Counter(l)
    p = c.most_common()[0][0]
    pp = c.most_common()[0][1]

    aa = []

    for c in itertools.combinations(range(N), 2):
        x1 = x[c[0]]
        y1 = y[c[0]]
        x2 = x[c[1]]
        y2 = y[c[1]] 

        if x1 - x2 < 0:
            xtmp, ytmp = x2, y2
            x2, y2 = x1, y1
            x1, y1 = xtmp, ytmp

        if (x1-x2, y1-y2) == p:
            aa.append(c)

    assert(len(aa) == pp)

    ll = [0] * N
    curG = 0
    for i in range(pp):
        if (ll[aa[i][0]] != 0):
            ll[aa[i][1]] = ll[aa[i][0]]
        elif (ll[aa[i][1]] != 0):
            ll[aa[i][0]] = ll[aa[i][1]]
        else:
            curG += 1
            ll[aa[i][0]] = curG
            ll[aa[i][1]] = curG

    k = 1 if 0 in ll else 0

    ccc = len(set(ll)) - k

    z = ll.count(0)

    inter = (N - z) - ccc

    print(N-inter)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
for i in range(n):
    a = list(input().split())
    xy.append(a)

#print(xy)
s = n
for i in range(n-1):
    for j in range(i+1,n):
        p = int(xy[i][0])-int(xy[j][0])
        q = int(xy[i][1])-int(xy[j][1])
        m = n
        #print(p)
        #print(q)
        for c in range(n-1):
            for b in range(c+1,n):
                #print(int(xy[c][0])-int(xy[b][0]))
                if abs(p) == abs(int(xy[c][0])-int(xy[b][0])) and abs(q) == abs(int(xy[c][1])-int(xy[b][1])):
                    m -= 1
                #print(m)
                
        if s>m:
            s = m
        #print("s"+ str(s))

print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

if N == 1:
    print(1)
else:
    d = []
    for i, pp1 in enumerate(p):
        for j in range(i + 1, N):
            pp2 = p[j]
            d.append((pp1[0] - pp2[0], pp1[1] - pp2[1]))

    c = Counter(d)

    print(N - c.most_common()[0][1])

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):
        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 logging
import numpy as np

logging.disable(logging.CRITICAL)
logging.basicConfig(level=logging.INFO, format = " %(message)s")

def max_counter(diffs):
    num = []
    for i in diffs:
        num.append(diffs.count(i))

    return max(num)
        
        
def main():
    N = int(input())

    if N == 1:
        print(1)
    else:
        balls = []
        for i in range(0, N):
            balls.append([int(x) for x in input().split()])
            
            ball_array = np.array(balls)    
        logging.info(ball_array)
        
        p_q = []
        for i in range(0, N - 1):
            diff = list(ball_array[i] - ball_array[i + 1])
            if 0 not in diff:
                p_q.append(diff)

                logging.info(p_q)

        print(N - max_counter(p_q))

          
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = sorted([list(map(int, input().split())) for _ in range(n)])
if n==1:
  print(1)
else:
  def cal(xy):
    print(xy)
    dis = [0] * (n-1)
    a,b = xy[0]
    for idx,(x,y) in enumerate(xy[1:]):
      dis[idx] = (x-a,y-b)
      a,b = x,y
    
    return n - max([dis.count(tuple(i)) for i in set(dis)])
  
  print(min(cal(xy),cal(sorted(xy,key=lambda x:x[1]))))

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = sys.stdin.readline
n = int(input())
xy = []
for i in range(n):
    _a,_b = map(int,input().split())
    xy.append([_a,_b])
sxy = sorted(xy)
sxy2 = []
sxy2.append(9999)
for i in range(1,n):
    sxy2.append(((sxy[i][0]-sxy[i-1][0])**2)+((sxy[i][1]-sxy[i-1][1])**2))
c = collections.Counter(sxy2)
ans = len(sxy2)-max(c.values())+1
print(ans) if ans != 0 else print(1)

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]))
d1 = []
for i in range(1, N):
    x = xy[i-1][0] - xy[i][0]
    y = xy[i-1][1] - xy[i][1]
    d1.append((x, y))
P1 = 0
for D in d1:
    P1 = max(d1.count(D), P1)

ans = N - P1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
answer = []
answer2 = []
lis = []
lis2 = []
for i in range(N):
    x, y = map(int, input().split())
    lis.append([x, y])
    lis2.append([y, x])
sort_lis = sorted(lis)
sort_lis2 = sorted(lis2)

if N == 1:
    print(1)
    exit()
for i in range(N-1):
    answer.append([sort_lis[i][0] -sort_lis[i+1][0],sort_lis[i][1]-sort_lis[i+1][1]])
    answer2.append([sort_lis2[i][0] -sort_lis2[i+1][0],sort_lis2[i][1]-sort_lis2[i+1][1]])
ans = list(map(tuple,answer))
#print(ans)
ans2 = list(map(tuple,answer2))
#print(ans2)
a = Counter(ans).most_common()
#print(a)
a2 = Counter(ans2).most_common()
#print(a2)
if a[0][1] > a2[0][1]:
    c = 1
    for i in range(1,len(a)):
        c += a[i][1]
else:
    c = 1
    for i in range(1,len(a2)):
        c += a2[i][1]
print(c)

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)



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 :
    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
    ret = min(tmp, ret)
    
print(ret)

Submission status: Wrong Answer

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

stock=[]

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

stock.sort(key=lambda x:(x[0],x[1]))
counter=0
ans=0
for i in range(1,len(stock)):

    if stock[i]==stock[i-1]:
        counter+=1
    else:
        ans=max(ans,counter)
        counter=0
ans=max(ans,counter)
print(N-ans-1)

Submission status: Wrong Answer

Solution code:
#XY = [[1,2],[1,1],[2,2],[2,1],[3,1],[3,2]]
#XY.sort()
#N = len(XY)
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
XY.sort()
cnt = 1
n=0
for i in range(N-1):
    xy = XY.pop(n)
    #print(XY)
    flag = False
    for k in range(len(XY)):
        if xy[0] != XY[k][0] and xy[1] != XY[k][1]:
            n = k
            #print("aa")
            flag=True
            break
    if flag ==False:
        #print("bb")
        cnt +=1
        n=0
print(cnt)

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)



if __name__ == "__main__":
	main()

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

x_dif = []
y_dif = []

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


result = []
res_ap = result.append
for i in range(len(x_dif)):
    if x_dif[i] == y_dif[i]:
        res_ap(x_dif[i])
    else:
        continue

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

print(N - (cnt - 1))

Submission status: Wrong Answer

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

if n == 1:
    print(1)

else:
    L_sort = sorted(L)
    L_dict = {}
    for i in range(n-1):
        tmp0 = L_sort[i+1][0] - L_sort[i][0]
        tmp1 = L_sort[i+1][1] - L_sort[i][1]
        if (tmp0, tmp1) in L_dict:
            L_dict[(tmp0, tmp1)] += 1
        else:
            L_dict[(tmp0, tmp1)] = 1

    
    ans = n - max(L_dict.values())
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
for i in range(n):
    a = list(input().split())
    xy.append(a)

#print(xy)
s = n
for i in range(n-1):
    for j in range(i+1,n):
        p = int(xy[i][0])-int(xy[j][0])
        q = int(xy[i][1])-int(xy[j][1])
        m = n
        #print(p)
        #print(q)
        for c in range(n-1):
            for b in range(c+1,n):
                #print(int(xy[c][0])-int(xy[b][0]))
                if abs(p) == abs(int(xy[c][0])-int(xy[b][0])) and abs(q) == abs(int(xy[c][1])-int(xy[b][1])):
                    m -= 1
                print(m)
                
        if s>m:
            s = m
        print("s"+ str(s))

print(s)