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())
balls = [list(map(int, input().split(" "))) for i in range(N)]
balls.sort()

vec = []
for i in range(N-1):
    for j in range(i+1, N):
        vec.append((balls[j][0] - balls[i][0], balls[j][1] - balls[i][1]))
vec.sort()
cntmax = 1
cnt = 1
prev = None
for v in vec:
    if prev == v:
        cnt += 1
        cntmax = max(cnt, cntmax)
    else:
        cnt = 1
    prev = v
print(N - cntmax)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = []
for I in range(N):
    x,y = map(int,input().split())
    B.append([x,y])
B.sort()
Max = 0
for i in range(1,N):
    C = []
    for j in range(N-i):
        b = [B[j+i][0]-B[j][0],B[j+i][1]-B[j][1]]
        C.append(b)
    max = 0
    for l in C:
        a = C.count(l)
        if a > max:
            max = a
    if Max < max:
        Max = max
print(N - Max)

Submission status: Wrong Answer

Solution code:
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]

        group = []

        if p == 0 : # y = b
            for k in range(N) :
                group.append(ball[k][1])
        else :
            for k in range(N) :
                pb = p * ball[k][1] - q * ball[k][0]
                group.append(pb)
        count = set(group)
        ans = min(ans,len(count))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=n
for i in range(n):
  for j in range(i+1,n):
    p,q=arr[j][0]-arr[i][0],arr[j][1]-arr[i][1]
    if p==0 and q==0:
      continue
    cnt=0
    flag=[0]*n
    for k in range(n):
      if flag[k]==1:
        continue
      flag[k]=1
      tmp=1
      for l in range(k,n):
        check=0
        if p==0:
          if arr[l][0]==arr[k][0]:
            check+=1
        elif p>0:
          if (arr[l][0]-arr[k][0])>0 and (arr[l][0]-arr[k][0])%p==0:
            check+=1
        else:
          if (arr[l][0]-arr[k][0])<0 and (arr[l][0]-arr[k][0])%p==0:
            check+=1
        if q==0:
          if arr[l][1]==arr[k][1]:
            check+=1
        elif q>0:
          if (arr[l][1]-arr[k][1])>0 and (arr[l][1]-arr[k][1])%q==0:
            check+=1
        else:
          if (arr[l][1]-arr[k][1])<0 and (arr[l][1]-arr[k][1])%q==0:
            check+=1
        if check==2:
          flag[l]=1
      cnt+=1
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools


def main():
  n = int(input())
  p = [tuple(map(int, input().split())) for _ in range(n)]
  c = {}

  if n == 1:
    print(1)
    return

  for i, j in itertools.combinations(range(len(p)), 2):
    d = (p[j][0] - p[i][0], p[j][1] - p[i][1])

    if d not in c:
      c[d] = 1
    else:
      c[d] += 1

  print(len(p) - max(c.values()))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import numpy as np
from collections import Counter
ls_x = []
ls_y = []
diff = []
N = int(input())
for n in range(N):
    x,y = map(int,input().split())
    for i in range(len(ls_x)):
        diff.append(str(ls_x[i] - x)+str(ls_y[i] - y))
    ls_x.append(x)
    ls_y.append(y)
if N == 1:
    print (1)
    exit()
cnt = Counter(diff)
print (N-cnt.most_common(1)[0][1])

Submission status: Wrong Answer

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

point.sort(key=lambda x: x[1])
point.sort(key=lambda x: x[0])

ans = float("inf")
for i in range(n - 1):
    for j in range(1, n - i):
        p = point[i + j][0] - point[i][0]
        q = point[i + j][1] - point[i][1]
        num = 1
        for k in range(n - 1):
            if point[k][0] + p == point[k + 1][0] and point[k][1] + q == point[k + 1][1]:
                num = num
            else:
                num += 1
        ans = min(ans, num)

point.sort(key=lambda x: x[1])
for i in range(n - 1):
    for j in range(1, n - i):
        p = point[i + j][0] - point[i][0]
        q = point[i + j][1] - point[i][1]
        num = 1
        for k in range(n - 1):
            if point[k][0] + p == point[k + 1][0] and point[k][1] + q == point[k + 1][1]:
                num = num
            else:
                num += 1
        ans = min(ans, num)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ret = float('inf')
for i in range(n - 1):
    for j in range(i + 1, n):
        p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
        if p == 0 and q == 0:
            continue
        cost = 1
        for k in range(1, n):
            if [a[k][0] - p, a[k][1] - q] != a[k - 1]:
                cost += 1
        ret = min(ret, cost)
print(ret)

Submission status: Wrong Answer

Solution code:
x = []
y = []

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

count = 1

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

p = x[1] - x[0]
q = y[1] - y[0]

# print("p, q = ", p, q)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
#
# xy.sort()
# xy = xy[::-1]
# sa = []
# for i in range(1, n):
#     sa.append([xy[i - 1][0] - xy[i][0], xy[i - 1][1] - xy[i][1]])
#
# xy.sort(key=lambda x:x[1])
# xy2 = xy
# print(xy2)
# xy2 = xy2[::-1]
# sa2 = []
# for i in range(1, n):
#     sa2.append([xy[i - 1][0] - xy[i][0], xy[i - 1][1] - xy[i][1]])
# print(sa, sa2)

sa = []
for i, j in xy:
    for k, l in xy:
        sa.append([i - k, j - l])

#sa1

xy.sort()
xy = xy[::-1]
ans = 10000000000000000000
i = 0
while True:
    if i >= len(sa):
        break
    if sa[i] == [0, 0]:
        del sa[i]
        i -= 1
    i += 1
    
    
for p, q in sa:
    tmp = 1
    for i in range(1, n):
        x = xy[i][0]
        y = xy[i][1]
        if xy[i - 1][0] == x - p and xy[i - 1][1] == y - q:
            1
        else:
            tmp += 1
    ans = min(ans, tmp)
xy.sort(key=lambda x:x[1])

for p, q in sa:
    tmp = 1
    for i in range(1, n):
        x = xy[i][0]
        y = xy[i][1]
        if xy[i - 1][0] == x - p and xy[i - 1][1] == y - q:
            1
        else:
            tmp += 1
    ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

ans = N
for i in range(N):
    for j in range(i+1, N):
        p, q = balls[i][0]-balls[j][0], balls[i][1]-balls[j][1]
        useds = [False] * N
        num = 0
        for a in range(N):
            if useds[a]: continue
            useds[a] = True
            num += 1
            for b in range(a+1, N):
                if useds[b]: continue
                if q*(balls[a][0]-balls[b][0]) == p*(balls[a][1]-balls[b][1]):
                    useds[b] = True
        ans = min(ans, num)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
z=[]
for i in range(n):
    x,y=map(int,input().split())
    z.append([x,y])
z.sort(reverse=True)
dif=[]
for i in range(n-1):
    x=z[i+1][0]-z[i][0]
    y=z[i+1][1]-z[i][1]
    dif.append([x,y])
dif.sort(reverse=True)
count=-1
buf=0
comp=[0,0]
ans=[0,0]
for i in range(n-1):
    if comp==dif[i]:
        buf+=1
    else:
        if count<buf:
            count=buf
            ans=comp
        buf=1
        comp=dif[i]
if count<buf:
    count=buf
    ans=comp
print(n-count)

Submission status: Wrong Answer

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

ans = N - 1
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = P[i]
        xj, yj = P[j]

        tmp = 1
        if xj == xi:
            for x, y in P:
                if x != xi:
                    tmp += 1
        else:
            K = (yj - yi) / (xj - xi)
            for x, y in P:
                if x == xi:
                    continue
                if (y - yi) / (x - xi) == K:
                    tmp += 0
                else:
                    tmp += 1

        ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
d = collections.defaultdict(int)
x,y = [10**10,10**10]
for i in range(n):
    nx,ny = Is()
    diff = nx - x, ny - y
    d[tuple(diff)] += 1
    x,y = nx,ny
d = d.items()
maxi = 0
for e in d:
    maxi = max(maxi,e[1])
print(n-maxi)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xlist = set()
ylist = set()
for i, (x, y) in enumerate(xy):
    if i == 0:
        tmpx = x
        tmpy = y
        continue
    xlist.add(abs(tmpx-x))
    ylist.add(abs(tmpy-y))
    tmpx = x
    tmpy = y
print(max(len(xlist),len(ylist)))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
if n==1:
  print(1)
else:
  for iii in range(n):
    l.append(list(map(int,input().split())))
  dic={}
  for iii in range(n):
    for jjj in range(iii+1,n):
      if l[iii][0]-l[jjj][0]>=0:
        a=str(l[iii][0]-l[jjj][0])+"_"+str(l[iii][1]-l[jjj][1])
      else:
        a=str(l[jjj][0]-l[iii][0])+"_"+str(l[jjj][1]-l[iii][1])
      if a not in dic:
        dic[a]=0
      else:
        dic[a]+=1
  b=max(dic.values())
  print(n-b-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
	x, y = map(int, input().split())
	a.append((x, y))
d = {}
if n == 1:
	print(0)
	exit()
a = sorted(a)
for i in range(n):
	tc = a[i]
	for j in range(i + 1, n):
		nd = a[j]
		x1, y1, = tc[0], tc[1]
		x2, y2, = nd[0], nd[1]
		rz1 = x1 - x2
		rz2 = y1 - y2
		d[(rz1, rz2)] = d.get((rz1,rz2), 0) + 1
print(n - max(d.values()))

Submission status: Wrong Answer

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


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

PQ=[]

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



for i in range(N-1):
    x1,y1=B[i]
    for j in range(i+1,N):
        x2,y2=B[j]

        u,v=x2-x1,y2-y1
        g=gcd(u,v)

        PQ.append((u//g,v//g))

PQ=list(set(PQ))


C=[b[0] for b in B]
ANS=len(set(C))

#print(ANS)

from fractions import Fraction

for p,q in PQ:
    if p==0:
        continue
    C=set()
    for x,y in B:
        C.add(y-x*Fraction(q, p))

    ANS=min(ANS,len(C))

print(ANS)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict
def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]

    # kari = defaultdict(set)

    # visit_list = [0 for i in range(num)]

    ans = num
    for i in range(num):
        for j in range(num):
            if i == j:
                continue

            now_kyori = [data[i][0] - data[j][0], data[i][1] - data[j][1]]
            visit_list = [0 for i in range(num)]
            visit_list[i], visit_list[j] = 1, 1

            kari_num = 1

            for k in range(num):
                if k == i:
                    continue
                now_data = data[k]

                flg = 1

                for l in range(num):
                    if visit_list[l]:
                        a = data[l][0] - now_data[0]
                        b = data[l][1] - now_data[1]

                        if now_kyori[0] == 0 and now_kyori[1] == 0:
                            if a == now_kyori[0] and b == now_kyori[0]:
                                flg = 0
                        elif now_kyori[0] == 0:
                            if a == now_kyori[0] and b % now_kyori[1] == 0:
                                flg = 0
                        elif now_kyori[1] == 0:
                            if b == now_kyori[1] and a % now_kyori[0] == 0:
                                flg = 0
                        else:
                            if a % now_kyori[0] == 0 and b % now_kyori[1] == 0:
                                if a // now_kyori[0] == b // now_kyori[1]:
                                    flg = 0
                        if flg == 0:
                            break

                if flg:
                    kari_num += 1
                visit_list[l] = 1


            ans = min(kari_num, ans)

    print(ans)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import atexit
import io
import sys

buff = io.BytesIO()
sys.stdout = buff


@atexit.register
def write():
    sys.__stdout__.write(buff.getvalue())

n = input()
d = {}
l = []
for i in xrange(n):
	x,y = map(int, raw_input().split())
	d[(x,y)] = i
	l.append((x,y))
l.sort()
ans = int(1e18)
for i in xrange(n):
	for j in xrange(n):
		if i == j:
			continue
		curr = 0
		flag = [0 for k in xrange(n)]
		p = l[j][0] - l[i][0]
		q = l[j][1] - l[i][1]
		for k in xrange(n):
			if flag[k]:
				continue
			curr += 1
			index = k
			flag[k] = 1
			while True:
				next_x = l[index][0] + p
				next_y = l[index][1] + q
				if (next_x, next_y) in d:
					if flag[d[(next_x, next_y)]] == 1:
						break
					flag[d[(next_x, next_y)]] = 1
				else:
					break
				index = d[(next_x, next_y)]
		ans = min(ans, curr)
print ans

Submission status: Wrong Answer

Solution code:
n = int(input())


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


listA = []
while True:
    try:
        listA.append(list(map(int, input().split())))

    except:
        break

setA = []

tmp = listA[-1]
for i in reversed(listA):
    setA.append([tmp[0]-i[0], tmp[1]-i[1]])
    tmp = i

print(len(get_unique_list(setA))-1)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alllist = []
minaslist = []
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])**3 - (alllist[i+1][1]-alllist[i][1])**4)



ans = collections.Counter(minaslist)
print(len(ans))

Submission status: Wrong Answer

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

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

ans = 5000

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

print(ans)

Submission status: Wrong Answer

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

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

memo = False
ans = 1e9+7
for x, y in diff:
  cost = 1
  for X, Y in XY:
    if not memo:
      memo = (X, Y)
      continue
    if (X - x, Y - y) == memo:
      pass
    else:
      cost += 1
    memo = (X, Y)
  ans = min(cost, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
para = [[i for i in map(int,input().split())] for j in range(N)]
x_dif = {}
y_dif = {}
for i in range(N-1):
    a = para[i+1][0] - para[i][0]
    if a in x_dif :
        x_dif[a]+= 1
    else :
        x_dif[a] = 1
for i in range(N-1):
    if para[i+1][1] - para[i][1] in y_dif :
        y_dif[para[i+1][1] - para[i][1]] += 1
    else :
        y_dif[para[i+1][1] - para[i][1]] = 1
p = 0
q = 0
for i in x_dif.keys():
    if p <= x_dif[i] :
        p = i
    else : pass
for i in y_dif.keys():
    if q <= y_dif[i]:
        q = i
    else : pass

ans  = 1
for i,j in zip(x_dif,y_dif):
    if p == i and q == j :
        pass
    else :
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
xy=list(list(map(int,input().split())) for _ in range(N))
L=[]
c=1
for i in range(1,N):
    L.append([xy[i][0]-xy[i-1][0],xy[i][1]-xy[i-1][1]])
for l in L:
    c=max(c,L.count(l))
print(N-c)

Submission status: Wrong Answer

Solution code:
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]

        group = []

        if p == 0 : # y = b
            for k in range(N) :
                group.append(ball[k][1])
        else :
            for k in range(N) :
                b = ball[k][1] - float(q) / float(p) * ball[k][0]
                group.append(round(b,8)) # 四捨五入
        count = set(group)
        ans = min(ans,len(count))

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, x: "List[int]", y: "List[int]"):
    x, y = zip(*sorted(list(zip(x, y))))
    p_cand = set([-x[i+1]+x[i] for i in range(N-1)])
    q_cand = set([-y[i+1]+y[i] for i in range(N-1)])

    minimum = INF
    for p in p_cand:
        for q in q_cand:
            # print("p: {}, q: {}".format(p, q))
            xy = list(zip(x, y))
            cost = 0
            while len(xy) > 0:
                # print(xy)
                xx, yy = xy.pop()
                cost += 1
                while (xx+p, yy+q) in xy:
                    xy.remove((xx+p, yy+q))
                    xx += p
                    yy += q
            # print("cost: {}".format(cost))
            if minimum > cost:
                minimum = cost
                # print(p, q, cost)
    print(minimum)

    return


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:
def cul(p,q):
    tmp=0
    for i in range(1,N):
        for j in range(i):
            if abs(a[i][0]-a[j][0])==p and abs(a[i][1]-a[j][1])==q: tmp+=1
    return N-tmp

N=int(input())
dic={}
ans=100
a=[list(map(int,input().split())) for i in range(N)]

for i in range(1,N):
    for j in range(i):
        if a[i][0]==a[j][0] or a[i][1]==a[j][1]: continue
        p,q=abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])
        ans=min(ans,cul(p,q))
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]
li = []
for i in range(1,n):
    li.append((abs(xy[i-1][0]-xy[i][0]),abs(xy[i-1][1]-xy[i][1])))

cnt = 0
p,q = 0,0
#print()
for k,v in Counter(li).items():
    #print(k,v)
    if cnt < v:
        cnt = v
        p,q = k

#print(p,q)
ans = 1
for i in range(1,n):
    if (xy[i][0]-p,xy[i][1]-q) != (xy[i-1][0],xy[i-1][1]):
        ans += 1
print(ans)

Submission status: Wrong Answer

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

d = {(-1, -1): 0}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        x3, y3 = x2-x1, y2-y1
        if x3 < 0:
            x3, y3 = -1*x3, -1*y3
        pos = (x3, y3)
        if pos not in d:
            d[pos] = 0
        d[pos] += 1

# print(d.values())
print(N - max(d.values())//2)

Submission status: Wrong Answer

Solution code:
N=int(input())
data=[]
for i in range(0,N):
  a,b=map(int,input().split())
  data.append([a,b])
  
#print(data)

dalta_data=[]
for i in range(0,N-1): #iは比較親
  Ai=data[i]
  for j in range(i+1,N): #jは比較子
    Aj=data[j]
    x=Ai[0]-Aj[0]
    y=Ai[1]-Aj[1]
    dalta_data.append([x,y])
    
#print(dalta_data)
    
M=len(dalta_data)
maxx=0
for i in range(0,M-1):
  max1=0
  for j in range(0,M):
    if dalta_data[i]==dalta_data[j] and i!=j:
      max1=max1+1
    else:
      di=dalta_data[i]
      dj=dalta_data[j]
      if di[0]==-dj[0] and di[1]==-dj[1]:
        max1=max1+1
  if max1>maxx:
    maxx=max1
  
print(N-maxx-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
	x, y = map(int, input().split())
	a.append((x, y))
d = {}
if n == 1:
	print(0)
	exit()
for i in range(n):
	tc = a[i]
	for j in range(i + 1, n):
		nd = a[j]
		x1, y1, = tc[0], tc[1]
		x2, y2, = nd[0], nd[1]
		rz1 = abs(x1- x2)
		rz2 = abs(y1 - y2)
		d[(rz1, rz2)] = d.get((rz1,rz2), 0) + 1
print(n - max(d.values()))

Submission status: Wrong Answer

Solution code:
from itertools import count, combinations
N = int(input())

balls = set(tuple(map(int,input().split())) for _ in range(N))


def solve(p,q, limit, balls):
    cost = 0
    while balls:
        cost += 1
        if cost >= limit:
            return limit

        x,y = next(iter(balls))
        balls.discard((x,y))
        try:
            for n in count(1):
                balls.remove((x-n*p, y-n*q))
        except KeyError:
            pass

        try:
            for n in count(1):
                balls.remove((x+n*p, y+n*q))
        except KeyError:
            pass
    return cost

cost = 100
for (a,b),(c,d) in combinations(sorted(balls), 2):
    cost = solve(a-c, b-d, cost, balls.copy())
print(cost)

Submission status: Wrong Answer

Solution code:
N = input()
N = int(N)
s = [[ int(i) for i in input().split()] for i in range(N)]
hoge = []
import collections

for i in s:
    for k in s:
        if k != i:
            hoge1 = (i[0] - k[0],i[1] - k[1])
            if hoge1[0] < 0:
                hoge1 = (k[0] - i[0],k[1] - i[1])
            hoge.append(hoge1)
if len(hoge) >= 1:
	c = collections.Counter(hoge)
	print(N - c.most_common()[0][1] // 2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque, defaultdict
from operator import itemgetter, xor, mul

import sys
#input = sys.stdin.readline
from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
g0 = itemgetter(0)
N = int(input())
X, Y = [0]*N, [0]*N
P = []
for i in range(N):
    P.append(inpl())
P = sorted(P)
for i in range(N):
    X[i], Y[i] = P[i]

U = [(X[i]-X[j], Y[i] - Y[j])for i in range(N) for j in range(N) if i != j]
D = defaultdict(int)
for i in range(N):
    D[(X[i], Y[i])] = i+1

ans = N+1
for ux, uy in U:
    if ux < 0:
        continue
    tmp = 0
    searched = [0]*(N)
    for i in range(N):
        if not searched[i]:
            tmp += 1
            searched[i] = 1
        j = D[(X[i]+ux), (Y[i]+uy)]
        if j:
            searched[j-1] = 1
    ans = min(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

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

xy = np.array(xy)

count_dic = {}
xy.sort()
for i in range(N):
    for j in range(i+1,N):
        diff = xy[i] - xy[j]
        p,q = diff
        pq = str(p)+str(q)
        if pq in count_dic:
            count_dic[pq] += 1
        else:
            count_dic[pq] = 1
# print(count_dic)
ans = 1
for k,v in sorted(count_dic.items(), key = lambda x:-x[1]):
    ans = N - v
    break
print(max(1,ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

diff = []
for i in range(n):
    for j in range(n):
        if i > j:
            diff.append(str(xy[i][0] - xy[j][0])+'and'+str(xy[i][1] - xy[j][1]))

ans = 0
for i in set(diff):
    cnt = diff.count(i)
    if ans < cnt:
        ans = cnt

print(n - ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = sorted([tuple(map(int, input().split())) for _ in range(N)], reverse=True)
PQ = []
for i in range(N-1):
    PQ.append((XY[i][0]-XY[i+1][0], XY[i][1]-XY[i+1][1]))
ans = N
for p, q in PQ:
    tmp = N
    for i in range(N-1, 0, -1):
        #print(XY[i-1][0]-p, XY[i][0], XY[i-1][1]-q, XY[i][1])
        if XY[i-1][0] - p == XY[i][0] and XY[i-1][1] - q == XY[i][1]:
            tmp -= 1
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

diffs = [(P[j][0] - P[i][0], P[j][1] - P[i][1]) for i in range(n) for j in range(i+1,n)]

mini = 1e100
for p,q in diffs:
    if (p,q) == (0,0):
        continue
    count = n
    for i in range(n):
        for j in range(i+1,n):
            if (P[i][0]+p, P[i][1]+q) == (P[j][0], P[j][1]):
                count -= 1
    mini = min(count, mini)

if n == 1:
    print(1)
else:
    print(mini)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N = int(input())
point = [tuple(map(int, input().split())) for _ in range(N)]

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

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    if sx-fx < 0 or sy-fy < 0:
        continue
    else:
        ans[(sx-fx, sy-fy)] += 1
if len(ans.most_common()) == 0:
    print(N)
else:
    print(max(1, N - ans.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
dis = {}

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

for i in range(n-1) :
	s = str(int(x[i+1])-int(x[i])) + "," + str(int(y[i+1])-int(y[i]))
	if s in dis : dis[s] += 1
	else : dis[s] = 1

print(len(dis))

Submission status: Wrong Answer

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

dic = {}
for x1,y1 in xy:
    for x2,y2 in xy:
        if x1 == x2 and y1 == y2:
            continue
        dx = x2 - x1
        dy = y2 - y1
        key = "{},{}".format(dx,dy)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1

for k, v in sorted(dic.items(), key=lambda x: -x[1]):
    print(n-v)
    break

Submission status: Wrong Answer

Solution code:
def cul(p,q):
    tmp=0
    for i in range(1,N):
        for j in range(i):
            if abs(a[i][0]-a[j][0])==p and abs(a[i][1]-a[j][1])==q: tmp+=1
    return N-tmp

N=int(input())
dic={}
ans=100
a=[list(map(int,input().split())) for i in range(N)]

for i in range(1,N):
    for j in range(i):
        if i==j or a[i][0]==a[j][0] or a[i][1]==a[j][0]: continue
        p,q=abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])
        ans=min(ans,cul(p,q))
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
#
# xy.sort()
# xy = xy[::-1]
# sa = []
# for i in range(1, n):
#     sa.append([xy[i - 1][0] - xy[i][0], xy[i - 1][1] - xy[i][1]])
#
# xy.sort(key=lambda x:x[1])
# xy2 = xy
# print(xy2)
# xy2 = xy2[::-1]
# sa2 = []
# for i in range(1, n):
#     sa2.append([xy[i - 1][0] - xy[i][0], xy[i - 1][1] - xy[i][1]])
# print(sa, sa2)

sa = []
for i, j in xy:
    for k, l in xy:
        sa.append([i - k, j - l])

#sa1

xy.sort()
xy = xy[::-1]
ans = 10000000000000000000
for p, q in sa:
    tmp = 1
    for i in range(1, n):
        x = xy[i][0]
        y = xy[i][1]
        if xy[i - 1][0] == x - p and xy[i - 1][1] == y - q:
            1
        else:
            tmp += 1
    ans = min(ans, tmp)
xy.sort(key=lambda x:x[1])
for p, q in sa:
    tmp = 1
    for i in range(1, n):
        x = xy[i][0]
        y = xy[i][1]
        if xy[i - 1][0] == x - p and xy[i - 1][1] == y - q:
            1
        else:
            tmp += 1
    ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X, Y = [], []
XY = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append((x, y))

XY.sort()
D = []
for i in range(1,N):
    D.append((XY[i][0] - XY[i - 1][0], XY[i][1] - XY[i - 1][1]))

DS = list(set(D))

cnt = 0
for d in DS:
    cnt = max(cnt, D.count(d))

res = N - cnt

XY.sort(key=lambda x: x[1])
D = []
for i in range(1,N):
    D.append((XY[i][0] - XY[i - 1][0], XY[i][1] - XY[i - 1][1]))

DS = list(set(D))

cnt = 0
for d in DS:
    cnt = max(cnt, D.count(d))

res = min(res, N-cnt)
print(res)