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:
# -*- 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
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
                for (px, py) in pre_exist.copy():
                    if (x, y) == (px, py):
                        found = True
                        continue
                    dx = px - x
                    dy = py - y
                    if (dx-p==0 and dy-q==0) or (dx+p==0 and dy+q==0):
                        found = True
                        break
                pre_exist.add((x,y))
                if not found:
                    mini_ans += 1
                        
            ans = min(ans, mini_ans)
    print(ans)
if __name__ == '__main__':
    main()

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
        break
      j +=1  
  except:
    for _ in range(N):
      if j > N-1:
        break
      if S[j][0]!=S[i][0]:
        ans+=1
        i = j
        break
      j+=1
print(ans)

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)

elif n == 2:
    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 = sorted([list(map(int, input().split())) for i in range(N)])

mincost = 10000000

for j,a in enumerate(xy): #O(N)
    for b in xy:
        p = a[0]-b[0]
        q = a[1]-b[1]
        prev = a
        check = [0]*N
        check[j] = 1
        cost = 1
        flag = True
        while flag:
            for i, c in enumerate(xy):
                if ([prev[0]-p,prev[1]-q]==c):
                    check[i] = 1
                    prev = c

            for i in range(N):
                if (not check[i]):
                    prev = xy[i]
                    check[i] = 1
                    cost += 1
                    break
                flag = False
        mincost = min(cost, mincost)   

print(mincost)

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

        A = set()
        B = set()
        for x, y in cord:
            A.add((x-p, y-q))
            B.add((x+p, y+q))

        ans = min(ans, len(A - cord), len(B - cord))

    return ans


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

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)

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

sorted(AB_list,key=lambda a:a[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:
print(0)

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([abs(xy[i][0] - xy[j][0]), abs(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])
        dif = result[i]

print(result)

print(N - (cnt - 1))

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
    pos.append(a)
    
print(N[0]-max(d.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
list1 = []
list2 = [0] * 2

for i in range(N):
    tmp1, tmp2 = map(int, input().split())
    list2[0] = tmp1
    list2[1] = tmp2
    list1.append(list2.copy())

list1.sort()
tmplist = []
tmp1 = list1[0][0]
tmp2 = list1[0][1]
for i in range(1, N):
    x1 = list1[i][0]
    y1 = list1[i][1]
    int1 = -(tmp1 - list1[i][0])
    int2 = -(tmp2 - list1[i][1])
    tmp1 = list1[i][0]
    tmp2 = list1[i][1]
    tmplist.append(str(int1) + ','+ str(int2))

maxcnt = 0
for i in range(len(tmplist)):
    maxcnt = max(maxcnt, tmplist.count(tmplist[i]))
print(N - maxcnt)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

def valid(steps):
    for i , x in enumerate(sorted(steps)):
        if i != x:
            return i - 1

    return len(steps) - 1
#
n = getN()
za = []
for i in range(n):
    za.append(getlist())
ans = 0
from collections import defaultdict
kumi = defaultdict(int)

for i, pa in enumerate(za):
    for j, pb in enumerate(za[i:]):
        xa, ya = pa
        xb, yb = pb
        dfx = xa - xb
        dfy = ya - yb

        diff = str(dfx) + str(dfy)
        kumi[diff] += 1

if n == 1:
    print(1)
    import sys;sys.exit()
del kumi["00"]
print(n - max(list(kumi.values())))
print(kumi)
# for p1 in za:
#     for p2 in za:
#         steps = []
#         if p1 == p2:
#             continue
#         xa, ya = p1
#         xb, yb = p2
#         dfx = xb - xa
#         dfy = yb - ya
#         if not (dfx or dfy):
#             continue
#         for p3 in za:
#             xc, yc = p3
#             if dfx:
#                 if (xc - xa) % dfx == 0:
#                     step = (xc - xa) // dfx
#                     if yc - ya == dfy * step:
#                         steps.append(step)
#
#             else:
#                 if xc == xa:
#                     if (yc - ya) % dfy == 0:
#                         steps.append((yc - ya) // dfy)
#         tmp = valid(steps)
#         print(p1, p2, tmp, steps)
#         if tmp > ans:
#             ans = tmp
#             if tmp == 3:
#                 print(p1, p2)
#
# print(n-ans)

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

    max_num = max(num)
    
    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 diff[0] != 0 or diff[1] != 0:
                p_q.append(diff)

                logging.info(p_q)

        print(N - max_counter(p_q))

          
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
AB =[]
for i in range(N):
    AB.append(list(map(int, input().split())))
AB.sort()
a = []
b = []
pre_AA=0
pre_BB=0
for i in AB:
    AA = int(i[0])
    a.append(abs(AA-pre_AA))
    BB = int(i[1])
    b.append(abs(BB-pre_BB))
    pre_AA = AA
    pre_BB = BB

a.sort()
b.sort()
temp_a = Counter(a)
#print(temp_a)
temp_b = Counter(b)
#print(temp_b)
p = temp_a.most_common()[0][0]
q = temp_b.most_common()[0][0]

#print(p)
#print(q)
cost = 1
pre_a = AB[0][0]
pre_b = AB[0][1]
for j in AB[1:]:
    a = int(j[0])
    b = int(j[1])
    if a-p == pre_a and b-q == pre_b:
        pre_a = a
        pre_b = b
        continue
    else:
        cost += 1
        pre_a = a
        pre_b = b
print(cost)

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)

elif n == 2:
    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

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

Submission status: Wrong Answer

Solution code:
import sys
from fractions import Fraction

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 = Fraction(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 = Fraction(diff_y, diff_x) if diff_x != 0 else 0
                    if abs(a) != abs(check_a):
                        continue

                    tmp = (points[try_j][1] + points[try_i][1]) - check_a * (
                        points[try_j][0] + points[try_i][0]
                    )
                    check_b = Fraction(tmp, 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:
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=abs(x[j]-x[i])
        q=abs(y[j]-y[i])

        for c in range(n):
            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:

N = int(input())
XY = []

for i in range(N):
    x, y = map(int, input().split(" "))
    XY.append((x, y))


Div_list = []

for i in range(N):
    x_i, y_i = XY[i]
    for j in range(i+1, N):
        x_j, y_j = XY[j]
        Div_list.append((abs(x_i - x_j), abs(y_i - y_j)))


Div_list_sorted = sorted(Div_list)

Div_list_len = len(Div_list_sorted)

count_max = 0
if Div_list_len == 1:
    count_max = 1
else:

    skip = 0

    for i in range(Div_list_len):
        count = 1
        if skip > 0:
            skip -= 1
            continue

        s_i = Div_list_sorted[i]
        if s_i[0] == 0 or s_i[1] == 0:
            continue

        for j in range(i+1, Div_list_len):
            s_j = Div_list_sorted[j]

            if s_i == s_j:
                count += 1

        skip = (count - 1)
        if count > count_max:
            count_max = count


print(N - count_max)

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(abs(val[1][0]-val[0][0])) + 'x' + str(abs(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:
#!/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[1],x[0]), reverse=True)

    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 = [i for i,v in csx.most_common()] + [-1*i for i,v in csx.most_common()]
    q = [i for i,v in csy.most_common()] + [-1*i for i,v in csy.most_common()]
    p.sort()
    q.sort()
    # print(p)

    ans = 10000000000
    for i in p:
        for j in q:
            if(i == 0 and j == 0):
                continue
            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:
# -*- coding: utf-8 -*-
import sys
import numpy as np
# 行数
N = int(input().strip())

# 2次元配列
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

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

Result=N-2

#print(grid)
for a in range(N):
    Re_t=1
    A = [grid[a][0],grid[a][1]]
    #print ("A equal")
    #print (A)
    for b in range(N):
        if a == b:
            continue
        B = [grid[b][0],grid[b][1]]
        #print ("B equal")
        #print (B)
        if (B[0]-A[0]) == 0:
        	k = 0
        else:
        	k = (B[1]-A[1])/(B[0]-A[0])
        #print ("katamuki")
        #print (k)
        for c in range(N):
            if (a == c) or (b == c):
                continue
            C = [grid[c][0],grid[c][1]]
            cy = B[1] + k*(C[0]-B[0])
            if cy == C[1]:
                continue
            else:
                Re_t = Re_t + 1
            #if Result <= Re_t:
            	#break
        if Result > Re_t:
            Result = Re_t
            #print ("result is overritten")
            #print (Result)
                
#print("end")
print (Result)

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))
    if len(ans) != 0:
        print(n - max(ans))
    else:
        print(n - 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
y=[]
count=0
for _ in range(n):
    xi,yi=map(int,input().split())
    x.append(xi)
    y.append(yi)

for i in range(n-2):
    if x[i+1]-x[i]==x[i+2]-x[i+1] and y[i+1]-y[i]==y[i+2]-y[i+1]:
        count+=0
    else:
        count+=1
if count==0:
    count=1
print(count)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import defaultdict
N = int(input())
B = [[0, 0] for i in range(N)]
D = [[[0, 0] for j in range(N)] for i in range(N)]
G = defaultdict(lambda:defaultdict(int))
for i in range(N):
  B[i] = [int(x) for x in input().split()]
B.sort()
for i in range(N):
  for j in range(i):
    grad = gcd(abs(B[j][0] - B[i][0]), abs(B[j][1] - B[i][1]))
    D[i][j] = [(B[j][0] - B[i][0]) // grad, (B[j][1] - B[i][1]) // grad]
    D[j][i] = [-D[i][j][0], -D[i][j][1]]
for i in range(N):
  for j in range(i, N):
    if i == j:
      continue
    G[str(D[i][j])][i] += 1
ans = N
for p in G.keys():
  ans = min(ans, N - len(G[p]))
print(ans)

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]==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:
            if l[i][0]!=0 and l[j][0]!=0:
                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 = int(input())
list1 = []
list2 = [0] * 2

for i in range(N):
    tmp1, tmp2 = map(int, input().split())
    list2[0] = tmp1
    list2[1] = tmp2
    list1.append(list2.copy())

list1.sort()
tmplist = []
tmp1 = list1[0][0]
tmp2 = list1[0][1]
for i in range(1, N):
    x1 = list1[i][0]
    y1 = list1[i][1]
    int1 = -(tmp1 - list1[i][0])
    int2 = -(tmp2 - list1[i][1])
    tmp1 = list1[i][0]
    tmp2 = list1[i][1]
    tmplist.append(str(int1) + ','+ str(int2))

maxcnt = 1
for i in range(len(tmplist)):
    maxcnt = max(maxcnt, tmplist.count(tmplist[i]))
print(N - maxcnt)

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)])
print(N-m)

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

    max_num = max(num)

    if max_num == 1:
        return 0
    else:
        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:
from collections import Counter as c
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda xy: xy[0])
if N == 1 or N == 2:
    print(1)
    exit()

inclination = []
for i in range(0, N-1):
    for j in range(i+1, N):
        inclination.append((XY[j][0] - XY[i][0], XY[j][1] - XY[i][1]))

p, q = sorted(list(c(inclination).items()),
              key=lambda x: x[1])[-1][0]

cnt_zero = 0
flag = [False]*N
for i in range(N):
    for j in range(i+1, N):
        if not flag[j] and XY[j][0] - XY[i][0] == p and XY[j][1] - XY[i][1] == q:
            cnt_zero += 1

print(N-cnt_zero)

Submission status: Wrong Answer

Solution code:
import math
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,14))
          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:
N=int(input())
dic=[]

for i in range(N):
    dic.append(input().split())
    dic[i][0] = int(dic[i][0])
    dic[i][1] = int(dic[i][1])
dic=sorted(dic, key=lambda x:(x[0],-x[1]))
#print(dic)

min=N
cnt=0
for i in range(N-1):
    p=dic[i+1][0]-dic[i][0]
    q=dic[i+1][1]-dic[i][1]
    if p==0 and q==0:
        cnt=0
    else:
            for k in range(N-1):
                if(dic[k+1][0]-p!=dic[k][0])or(dic[k+1][1]-q!=dic[k][1]):
                    cnt+=1
            #print(cnt)
            if(min>=cnt):
                min=cnt
    cnt=0
print(min+1)

Submission status: Wrong Answer

Solution code:
N=int(input())
x=[]
y=[]
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=51
for p,q in c:
    s=0
    for i in range(N):
        if (x[i]-p in x) and (y[i]-q in y):
            s+=1
    ans=min(ans,N-s)
print(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
                for (px, py) in pre_exist.copy():
                    if (x, y) == (px, py):
                        found = True
                        continue
                    dx = px - x
                    dy = py - y
                    if abs(dx) == abs(p) and abs(dy) == abs(q):
                        found = True
                        break
                pre_exist.add((x,y))
                if not found:
                    mini_ans += 1
                        
            ans = min(ans, mini_ans)
    print(ans)
if __name__ == '__main__':
    main()