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:
def deposit(p,q):
    ans_list = []
    temp_list = []
    before = [0,0]
    for i, v in enumerate(point_list):
        if i == 0:
            temp_list.append(v)
        else:
            if [before[0]+p,before[1]+q] == v:
                temp_list.append(v)
            else:
                ans_list.append(temp_list)
                temp_list = [v]
        before = v

    ans_list.append(temp_list)
    return len(ans_list)

n = int(input())
point_list = sorted([ [ int(v) for v in input().split() ] for i in range(n) ])

ans = n
for k in [ (i,j) for i in range(n) for j in range(i+1,n) ]:
    i, j = k
    p, q = point_list[j][0] - point_list[i][0], point_list[j][1] - point_list[i][1]
    ans = min(deposit(p,q),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

A1 = sorted(A, key=itemgetter(0))
P = []
pre = 0
for x1, y1 in A1:
    P.append(x1 - pre)
    pre = x1

A2 = sorted(A, key=itemgetter(1))
Q = []
pre = 0
for x2, y2 in A2:
    Q.append(y2 - pre)
    pre = y2

ans = N
for p in P:
    for q in Q:
        a = 0
        for i in range(N):
            xi, yi = A[i]
            for j in range(N):
                if j == i:
                    continue
                xj, yj = A[j]
                if xj - xi == p and yj - yi == q:
                    a += 1
        #print(p, q, a)
        ans = min(N-a, ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#diverta2019_2 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]
ans = float('inf')
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        p,q = xy[j][0] - xy[i][0],xy[j][1] - xy[i][1]
        cost = n
        for k in range(n):
            for l in range(n):
                a,b = xy[k][0] - xy[l][0],xy[k][1] - xy[l][1]
                #print('p',p,'q',q,'a',a,'b',b,'cost',cost)
                if p == a and q == b:
                    cost -= 1
        ans = min(cost,ans)
print(ans)

Submission status: Wrong Answer

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

rates = {0: 0}
for i in range(N):
    for j in range(i, N):
        if i == j:
            continue
        vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
        rates[vector] = rates.get(vector, 0) + 1

print(N - max(rates.values()))

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    rates = {0: 0}
    for j in range(N):
        if i == j:
            continue
        vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
        rates[vector] = rates.get(vector, 0) + 1
    ans = max(ans, max(rates.values()))

print(N - ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = []
br = []
for i in range(a):
    l = list(map(int,input().split(" ")))
    ar.append(l)
for i in range(1,a):
    br.append([ar[i-1][0]-ar[i][0],ar[i-1][1]-ar[i][1]])
mx = 0
for r in br:
    if mx < br.count(r):
        mx = br.count(r)
print(a-mx)

Submission status: Wrong Answer

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

d = []
c = []
for i in range(n):
    for j in range(n):
        tmp = [l[i][0]-l[j][0],l[i][1]-l[j][1]]
        if tmp not in d:
            d.append(tmp)
            c.append(1)
ans = n
for x in d:
    t = 1
    for i in range(1,n):
        former = l[i-1]
        now = l[i]
        if former[0]-x[0] == now[0] and former[1] - x[1] == now[1]:
            t += 0
        else:
            t += 1
    if t < ans:
        ans = t
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = []
b = []
for i in range(n):
    c,d = map(int,input().split())
    e = np.array([c,d])
    for j in range(len(a)):
        b.append(list(a[j]-e))
        b.append(list(e-a[j]))
    a.append(e)
f = []
for x in b:
    if x not in f:
        f.append(x)
m = -100
for i in range(len(f)):
    if b.count(f[i])>m:
        m = b.count(f[i])
print(n-m)

Submission status: Wrong Answer

Solution code:
import fractions
from collections import defaultdict
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
dic = defaultdict(set)
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    vec[0] = vec[0]
    vec[1] = vec[1]
    vec = tuple(vec)
    dic[vec].add(j)
m = 0
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)

Submission status: Wrong Answer

Solution code:
import fractions
from collections import defaultdict
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
dic = defaultdict(set)
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    if vec[0]<0:
      vec[0] = (-1)*vec[0]
      vec[1] = (-1)*vec[1]
    vec[0] = vec[0]
    vec[1] = vec[1]
    vec = tuple(vec)
    dic[vec].add(j)
m = 0
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
dic = {}
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    size = fractions.gcd(vec[0],vec[1])
    vec[0] = vec[0]//size
    vec[1] = vec[1]//size

    vec = tuple(vec)
    if vec not in dic.keys():
      dic[vec] = set([j])
    else:
      dic[vec].add(j)
m = 0
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
dic = {}
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    size = fractions.gcd(vec[0],vec[1])
    vec[0] = vec[0]//size
    vec[1] = vec[1]//size
    vec = tuple(vec)
    if vec not in dic.keys():
      dic[vec] = set([j])
    else:
      dic[vec].add(j)
m = 1
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)

Submission status: Wrong Answer

Solution code:
N=int(input())
x0,y0=map(int,input().split())

xylist=[]
for i in range(N-1):
  x,y=map(int,input().split())
  xylist.append((x-x0,y-y0))
  
#print(xylist)
min_cost = N
if N<=2:
  print(1)
else:
  for i in range(N-1):
    intercept_set = set()
    x,y = xylist[i]
    
    if x != 0:
      #slope = y/x
      slope = y
      for j in range(N-1):
        x2,y2 = xylist[j]        
        #intercept = y2-slope*x2
        intercept = y2-slope*x*x2
        intercept_set.add(intercept)
    else:
      for j in range(N-1):
        x2,y2 = xylist[j]
        intercept = x2
        intercept_set.add(intercept)
          
    min_cost = min(min_cost, len(intercept_set))
    
  print(min_cost)

Submission status: Wrong Answer

Solution code:
N=int(input())
x0,y0=map(int,input().split())

xylist=[]
for i in range(N-1):
  x,y=map(int,input().split())
  xylist.append((x-x0,y-y0))
  
#print(xylist)
min_cost = N
if N<=2:
  print(1)
else:
  for i in range(N-1):
    intercept_set = set()
    x,y = xylist[i]
    
    if x != 0:
      slope = y/x
      for j in range(N-1):
        x2,y2 = xylist[j]
        
        intercept = y2-slope*x2
        intercept_set.add(intercept)
    else:
      for j in range(N-1):
        x2,y2 = xylist[j]
        intercept = x2
        intercept_set.add(intercept)
          
    min_cost = min(min_cost, len(intercept_set))
    
  print(min_cost)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
points = []
for i, line in enumerate(sys.stdin):
    x, y = map(int, line.split())
    points.append([x, y])
    if i == N - 1:
        break
if len(points) == 1:
    print(0)
    sys.exit(0)

counts = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = points[j][0] - points[i][0]
        q = points[j][1] - points[i][1]
        counts.append((p, q))

pq = Counter(counts).most_common()[0][1]
cost = N - pq
print(cost)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
        x[i],y[i]=list(map(int,input().split()))
dic={}
if n==1:
        print(1)
        exit()
dic={}
for i in range(n):
        for j in range(i+1,n):
                dx=x[i]-x[j]
                dy=y[i]-y[j]
                if (dx,dy) in list(dic.keys()):
                        dic[(dx,dy)]+=1
                else:
                        dic[(dx,dy)]=1
print(n-max(list(dic.values())))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
        x[i],y[i]=list(map(int,input().split()))
if n==1:
        print(1)
        exit()
dic={}#p,qに対応するグラフの辺の数
for i in range(n):
        for j in range(i+1,n):
                dx=x[j]-x[i]
                dy=y[j]-y[i]
        if (dx,dy) not in dic:
                dic[(dx,dy)]=1
        else:
                dic[(dx,dy)]+=1
        dx*=-1
        dy*=-1
        if (dx,dy) not in dic:#dicに既にあるかを調べる
                dic[(dx,dy)]=1
        else:
                dic[(dx,dy)]+=1
ans=max(dic.values())
print(n-ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
coord=[list(map(int,input().split()))for i in range(n)]
coord=sorted(coord,key=lambda x:x[0])
diff=[[0,0]for i in range(n-1)]
for i in range(n-1):
        diff[i][0],diff[i][1]=coord[i+1][0]-coord[i][0],coord[i+1][1]-coord[i][1]
diff=list(map(list,set(map(tuple,diff))))
print(len(diff))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
        x[i],y[i]=list(map(int,input().split()))
diff=[[0,0]for i in range(n-1)]
for i in range(n-1):
        diff[i][0]=x[i+1]-x[i]
        diff[i][1]=y[i+1]-y[i]
diff=list(map(list,set(map(tuple,diff))))#重複をなくす
print(len(diff))

Submission status: Wrong Answer

Solution code:
import collections
import itertools
N = int(input())
balls =[list(map(int, input().split())) for _ in range(N)]
pq = collections.defaultdict(int)
for a, b in itertools.combinations(balls, 2):
    x1, y1 = a
    x2, y2 = b
    p = abs(x1-x2)
    q = abs(y1-y2)
    pq[(p, q)] += 1
cnt = 0
for c in pq.values():
    if c > cnt:
        cnt = c
ans = N-cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
balls = [[0]*2 for i in range(N)]
 
for i in range(N):
    balls[i][0], balls[i][1] = list(map(int, input().split()))
 
common_b = 0
 
for i in range(N):
    for j in range(i+1, N):
 
        tmp = 1
        x_base = balls[j][0]-balls[i][0]
        y_base = balls[j][1]-balls[i][1]
        for k in range(i+1,N):
            for l in range(k+1, N):
 
                if balls[l][1]-balls[k][1] == y_base and balls[l][0]-balls[k][0] == x_base:
                    tmp+=1
                    
        common_b = max(common_b, tmp)
 
print(N - common_b)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
balls = [[0]*2 for i in range(N)]
 
for i in range(N):
    balls[i][0], balls[i][1] = list(map(int, input().split()))
 
balls = sorted(balls, key=lambda x: x[0])
 
#1個のときは別に処理を書くこと
 
common_b = 0
 
for i in range(N):
    for j in range(i+1, N):
 
        tmp = 1
        x_base = balls[j][0]-balls[i][0]
        y_base = balls[j][1]-balls[i][1]
        for k in range(i+1,N):
            for l in range(k+1, N):
 
                if balls[l][1]-balls[k][1] == y_base and balls[l][0]-balls[k][0] == x_base:
                    tmp+=1
                    
        common_b = max(common_b, tmp)
 
print(N - common_b)

Submission status: Wrong Answer

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

key_freq = {}
for n in range(N):
    for k in range(n+1,N):
        nx, kx = xs[n], xs[k]
        key = (nx[0]-kx[0], nx[1]-kx[1])
        if key_freq.get(key) is None:
            key_freq[key] = 0
        key_freq[key] += 1

try:
    last_key_freq = sorted([(key,freq) for key, freq in key_freq.items()],key=lambda x:x[1])[-1]
except:
    print(1)
    exit()

max_freq = last_key_freq[1]
cs = []
for key, freq in key_freq.items():
    if max_freq != freq:
        continue
    #print(key)
    x_n ={}
    for x in xs:
        x_n[tuple(x)] = (x[0] + key[0],x[1]+key[1])
    c=0
    for x, n in x_n.items():
        if n in x_n:
            c+=0
        else:
            c+=1
    #print(c, key)
    cs.append(c)
print(min(cs))

Submission status: Wrong Answer

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

key_freq = {}
for n in range(N):
    for k in range(n+1,N):
        nx, kx = xs[n], xs[k]
        key = (nx[0]-kx[0], nx[1]-kx[1])
        if key_freq.get(key) is None:
            key_freq[key] = 0
        key_freq[key] += 1

try:
    key_freq = sorted([(key,freq) for key, freq in key_freq.items()],key=lambda x:x[1])[-1]
except:
    print(1)
    exit()

key = key_freq[0]
#print(key)
x_n ={}
for x in xs:
    x_n[tuple(x)] = (x[0] + key[0],x[1]+key[1])
c=0
for x, n in x_n.items():
    if n in x_n:
        c+=0
    else:
        c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())

balls = [[0]*2 for i in range(N)]

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

balls = sorted(balls, key=lambda x: x[0])

#1個のときは別に処理を書くこと

common_b = 0

for i in range(N):
    for j in range(i+1, N):

        tmp = 0
        x_base = balls[j][0]-balls[i][0]
        y_base = balls[j][1]-balls[i][1]
        for k in range(i,N):
            for l in range(k+1, N):

                if balls[l][1]-balls[k][1] == y_base and balls[l][0]-balls[k][0] == x_base:
                    tmp+=1
                    
        common_b = max(common_b, tmp)

print(N - common_b)

Submission status: Wrong Answer

Solution code:
N = int(input())

balls = [[0]*2 for i in range(N)]

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

balls = sorted(balls, key=lambda x: x[0])

#1個のときは別に処理を書くこと

common_b = 0

for i in range(N):
    for j in range(i, N):
        if i ==j:
            continue

        tmp = 0
        x_base = balls[j][0]-balls[i][0]
        y_base = balls[j][1]-balls[i][1]
        for k in range(N):
            for l in range(k, N):
                if k == l:
                    continue

                if balls[l][1]-balls[k][1] == y_base and balls[l][0]-balls[k][0] == x_base:
                    tmp+=1
                    
        common_b = max(common_b, tmp)

print(N - common_b)

Submission status: Wrong Answer

Solution code:
n,*t=map(int,open(0).read().split())
*z,=zip(t[::2],t[1::2])
m=10**18
for ax,ay in z:
  for bx,by in z:
    p,q=bx-ax,by-ay
    if not p+q:continue
    t=0
    for cx,cy in z:
      for dx,dy in z:
        if dx+p==cx and dy+q==cy:break
      else:t+=1
    if t<m:m=t
print(m)

Submission status: Wrong Answer

Solution code:
XY = [[1,2],[1,1],[2,2],[2,1]]
N = len(XY)
#N=int(input())
#XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)

Submission status: Wrong Answer

Solution code:
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
XY = [[1,2],[1,1],[2,2],[2,1],[3,1],[3,2]]
N = len(XY)
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = data2[-1][0]
print(N-d)

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 1:
    print(1)
else:
    xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
    d = {}
    for i in range(N):
        for j in range(i + 1, N):
            p = xy[i][0] - xy[j][0]
            q = xy[i][1] - xy[j][1]
            if (p, q) in d:
                d[(p, q)] += 1
            else:
                d[(p, q)] = 1
    print(N - max(d.values()))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
if N == 1:
    print(1)
    sys.exit()
xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
d = {}
for i in range(N):
    for j in range(i + 1, N):
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]
        if (p, q) in d:
            d[(p, q)] += 1
        else:
            d[(p, q)] = 1
print(N - max(d.values()))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from operator import itemgetter
n = int(input())
li = [list(map(int,input().split())) for _ in range(n)]
li = sorted(li,key = itemgetter(0))
lidiff = []

for pair in combinations(li,2):
  lidiff.append([pair[1][0] - pair[0][0],pair[1][1] - pair[0][1]])

maxcnt = 0
for diff in lidiff:
  cnt = 0
  for i in range(1,n):
    for j in range(i):
      if li[i][0] - li[j][0] == diff[0] and li[i][1] - li[j][1] == diff[1]:
        cnt += 1
  maxcnt = max(maxcnt,cnt)
print(n - maxcnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
items = list(set(d_list))
s = 1
for item in items:
    c = d_list.count(item)
    if c >= 2 and c > s:
        s = c
print(N - s)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
items = list(set(d_list))
s = 0
for item in items:
    c = d_list.count(item)
    if c >= 2 and c > s:
        s = c
print(N - s)

Submission status: Wrong Answer

Solution code:
def most_common(d_list):
    items = list(set(d_list))
    s = 0
    for item in items:
        c = d_list.count(item) - 1
        if c > s:
            s = c
    return s

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
d_list = [(XY[0] - xy[j][0], XY[1] - xy[j][1]) for i, XY in enumerate(xy) for j in range(i + 1, N)]
print(N - most_common(d_list))

Submission status: Wrong Answer

Solution code:
def most_common(d_list):
    items = list(set(d_list))
    s = 0
    for item in items:
        c = d_list.count(item)
        if c > s:
            s = c
    return s

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
# xy = sorted(dict(xy).items(), key=lambda x: x[0]) 
d_list = [(XY[0] - xy[j][0], XY[1] - xy[j][1]) for i, XY in enumerate(xy) for j in range(i + 1, N)]
print(N - most_common(d_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
if n <= 2:
    print( 1)
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

#points.sort()
while len(points) != 0:
    if len(points) <= 2:
        cost +=1
        break
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    #print(p, " ", q)
    while len(points) != 0 and xn >= points[-1][0] and yn >= points[-1][1]:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
        else:
            break
print(cost)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n <= 2:
    print( 1)
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

points.sort()
while len(points) != 0:
    if len(points) <= 2:
        cost +=1
        break
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    #print(p, " ", q)
    while len(points) != 0 and xn >= points[-1][0] and yn >= points[-1][1]:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
        else:
            break
print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
if N <= 2:
    print(1)
else:
    xy = []
    for _ in range(N):
        xy.append(list(map(int, input().split())))
    
    xy.sort()

    max_dup = 0
    for i in range(N-1):
        curr_i = xy[i]
        for j in range(i+1, N):
            curr_j =xy[j]
            p, q = curr_j[0] - curr_i[0], curr_j[1] - curr_i[1]
            
            cnt = 0
            for n in range(N):
                if n == 0:
                    continue
                if (xy[n][0]-xy[n-1][0] == p) and (xy[n][1]-xy[n-1][1] == q):
                    cnt += 1
            max_dup = max(max_dup, cnt)
    print('{}'.format(N-max_dup))

Submission status: Wrong Answer

Solution code:
N = int(input())
if N <= 2:
    print(1)
else:
    xy = []
    for _ in range(N):
        xy.append(list(map(int, input().split())))
    
    xy.sort()

    max_dup = 0
    for i in range(N):
        curr_i = xy[i]
        for j in range(i+1, N):
            curr_j =xy[j]
            p, q = curr_j[0] - curr_i[0], curr_j[1] - curr_i[1]
            
            cnt = 0
            for n in range(N):
                if n == 0:
                    continue
                if (xy[n][0]-xy[n-1][0] == p) and (xy[n][1]-xy[n-1][1] == q):
                    cnt += 1
            max_dup = max(max_dup, cnt)
    print('{}'.format(N-max_dup))

Submission status: Wrong Answer

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

if n==1:
    print(1)
    import sys
    sys.exit()
l=[]
ans=0
import itertools
for a,b in itertools.combinations(xy,2):
    p=abs(a[0]-b[0])
    q=abs(a[1]-b[1])
    if p!=0 or q!=0:
        l.append((p,q))

import collections
c=collections.Counter(l)
p=c.most_common()

for i in p:
   ans=max(ans,i[1])
print(n-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])

D={}
for i in range(N):
    for j in range(N):
        D[(L[i][0]-L[j][0],L[i][1]-L[j][1])]=1
#print(D)

ANS=N

for i in D.keys():
    cnt=0
    for j in range(len(L)-1):
        for k in range(j+1,len(L)):
            if i[0]==(L[j][0]-L[k][0]) and i[1]==(L[j][1]-L[k][1]):
                cnt+=1
    ANS=min(ANS,N-cnt)
print(ANS)

Submission status: Wrong Answer

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

if n==1:
    print(1)
    import sys
    sys.exit()
l=[]
ans=0
import itertools
for a,b in itertools.combinations(xy,2):
    p=abs(a[0]-b[0])
    q=abs(a[1]-b[1])
    if p!=0 or q!=0:
        l.append((p,q))

import collections
c=collections.Counter(l)
pp=c.most_common()
print(n-pp[0][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])

D={}
for i in range(N):
    for j in range(N):
        if i!=j:
            if (L[i][0]-L[j][0],L[i][1]-L[j][1]) not in D:
                D[(L[i][0]-L[j][0],L[i][1]-L[j][1])]=1
#print(D)

ANS=N

for i in D.keys():
    cnt=0
    for j in range(len(L)-1):
        for k in range(j+1,len(L)):
            if i[0]==(L[j][0]-L[k][0]) and i[1]==(L[j][1]-L[k][1]):
                cnt+=1
    ANS=min(ANS,N-cnt)
print(ANS)

Submission status: Wrong Answer

Solution code:
# diverta2-B
# ソートは必ずする必要がある
n=int(input())
if n==1:
	print(1)
	exit()
xy = [list(map(int,input().split())) for i in range(n)]
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):# i+1スタートなのがポイント
		p = abs(xy[i][0]-xy[j][0])
		q = abs(xy[i][1]-xy[j][1])
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))

Submission status: Wrong Answer

Solution code:
import sys

# from collections import Counter, deque, defaultdict
# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N = int(input())
# XY = set()
XY = []
for _ in range(N):
    x, y = [int(x) for x in input().split()]
    # XY.add((x,y))
    XY.append((x, y))

XY.sort()
ans = float("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]

        T = [0] * N
        for k in range(N):
            if T[k] != 0:
                continue
            T[k] = 1
            curXY = (XY[k][0], XY[k][1])

            for l in range(N):
                if (XY[l][0], XY[l][1]) == ((curXY[0] - p, curXY[1] - q)):
                    T[l] = 2
                    curXY = XY[l]

        # ans = min(T.count(1), ans)
        if ans > T.count(1):
            ans = T.count(1)
            ansP, ansQ = p, q
            # print("ans,p,q = {},{},{}".format(ans, p, q))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==1:
	print(1)
	exit()
xy = [list(map(int,input().split())) for i in range(n)]
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):
		p = xy[i][0]-xy[j][0]
		q = xy[i][1]-xy[j][1]
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))

Submission status: Wrong Answer

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

zm = []
XY.sort(key=lambda x:x[0])
XY.sort(key=lambda x:x[1])
for i in range(N - 1):
    a = XY[i][0] - XY[i + 1][0]
    b = XY[i][1] - XY[i + 1][1]
    zm.append((a, b))
from collections import Counter
print(N - Counter(zm).most_common(1)[0][1])

Submission status: Wrong Answer

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

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

dic = {}
for i in range(N):
    for j in range(i+1,N):
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        if (0>dx):
            dx *= -1
            dy *= -1
        if (0==dx & 0>dy):
            dy *= -1
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1

d_max = max(dic.values())
print(N - d_max)

Submission status: Wrong Answer

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

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

dic = {}
for i in range(N):
    for j in range(i+1,N):
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        if (0>dx):
            dx *= -1
            dy *= -1
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1

d_max = max(dic.values())
print(N - d_max)

Submission status: Wrong Answer

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

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

dic = {}
for i in range(N):
    for j in range(i+1,N):
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1

d_max = max(dic.values())
print(N - d_max)

Submission status: Wrong Answer

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

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

dic = {}
for i in range(N):
    for j in range(N):
        if i == j:
            break
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]

        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1

d_max = max(dic.values())
print(N - d_max)

Submission status: Wrong Answer

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

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

dic = {}
for i in range(N):
    for j in range(N):
        if i == j:
            break
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        if (0>dx):
            dx *= -1
            dy *= -1
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1

d_max = max(dic.values())
print(N - d_max)

Submission status: Wrong Answer

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

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

dic = {}
for i in range(N):
    for j in range(N-(i+1)):
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        if (0>dx):
            dx *= -1
            dy *= -1
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1

d_max = max(dic.values())
print(N - d_max)