Problem:


Score : 300 points

Problem Statement

There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).

We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation:

Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.

Find the minimum total cost required to collect all the balls when we optimally choose p and q.

Constraints

1 \leq N \leq 50

|x_i|, |y_i| \leq 10^9

If i \neq j, x_i \neq x_j or y_i \neq y_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum total cost required to collect all the balls.

Sample Input 1

2
1 1
2 2

Sample Output 1

1

If we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).

Sample Input 2

3
1 4
4 6
7 8

Sample Output 2

1

If we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).

Sample Input 3

4
1 1
1 2
2 1
2 2

Sample Output 3

2



Sample input:
2
1 1
2 2


Sample output:
1

Submission status: Wrong Answer

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

dx = [[10**10]*N for _ in [0]*N]
dy = [[10**10]*N for _ in [0]*N]
ps = set()
qs = set()
for i in range(N):
    for j in range(N):
        if i==j:continue
        dx[i][j] = xy[i][0] - xy[j][0]
        dy[i][j] = xy[i][1] - xy[j][1]
        ps.add(dx[i][j])
        qs.add(dy[i][j])
for i in range(N):
    dx[i] = set(dx[i][:i]+dx[i][i+1:])
    dy[i] = set(dy[i][:i]+dy[i][i+1:])

ans = 0
for p in ps:
    for q in qs:
        cnt = 0
        for i in range(N):
            if (p in dx[i]) and (q in dy[i]):
                cnt += 1
        ans = max(ans,cnt)

print(N-ans)

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    if n ==1:
        print(1)
    else:
        x_y_list=[]
        for i in range(n):
            x,y = map(int,input().split(' '))
            x_y_list.append((x,y))
        sorted_x_y = sorted(x_y_list)
        p_q_list=[]
        for i in range(n-1):
            for j in range(i,n):
                dif_x = sorted_x_y[i][0]-sorted_x_y[j][0]
                dif_y = sorted_x_y[i][1]-sorted_x_y[j][1]
                if dif_x != 0 and dif_y != 0:
                    p_q_list.append((dif_x,dif_y))
        p_q_list = list(set(p_q_list))
        p_q_max = 0
        for p,q in p_q_list:
            for i in range(n):
                tmp = 0
                x_i = sorted_x_y[i][0]
                y_i = sorted_x_y[i][1]
                for j in range(n):
                    if i ==j:
                        continue
                    x_j = sorted_x_y[j][0]
                    y_j = sorted_x_y[j][1]
                    if (x_j-x_i)%p == 0  and (y_j%q-y_i) == 0:
                        tmp += 1
                if tmp > p_q_max:
                    p_q_max = tmp
        print(n-p_q_max-1)

main()

Submission status: Wrong Answer

Solution code:
# 何本の数直線上にあるかを求める　1<=ans<=n-1
# 少なくとも2点を通る直線のみ調べれば良い
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
xy.sort(key=lambda x:(x[0],x[1]))
# print(xy)
if n<=2:
    print(1)
else:
    diff=[]
    for i in range(n):
        for j in range(i):
            diff.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))

    ans=[]
    # print(set(diff))
    for p,q in set(diff):
        intercept=[]
        for i in range(n):
            qxHIKUpy=q*xy[i][0]-p*xy[i][1]
            intercept.append(qxHIKUpy)
        # print(q,'x-',p,'y=',intercept)
        cnt=len(set(intercept))
        intercepts=sorted(enumerate(intercept),key=lambda x:x[1])
        # print(intercepts)
        i=0
        x=xy[intercepts[0][0]][0]
        intercept=intercepts[0][1]
        for i in range(1,n):
            if intercept==intercepts[i][1]:
                if x+p != xy[intercepts[i][0]][0]:
                    cnt+=1
            x=xy[intercepts[i][0]][0]
            intercept=intercepts[0][1]
            
        ans.append(cnt)
    # print(ans)
    print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
ball = [[int(i) for i in input().split()] for k in range(N)]
diff = []
if N == 1:
    print(1)
else:
    for i in range(N-1):
        for j in range(i+1, N):
            diff.append((abs(ball[i][n]-ball[j][n]) for n in range(2)))
    k = Counter(diff).most_common()[0][1]
    print(max(1,N-k))

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[]
a=[]
for i in range(n):
  b,c=(int(j) for j in input().split())
  for k in range(i):
    d=a[k][0]-b
    e=a[k][1]-c
    if d<0:
      d=-d
      e=-e
    r.append([d,e])
  a.append([b,c])
r.sort()
if n>1:
  p=r[0]
x=1
z=0
t=0
q=[]
for i in range(len(r)-1):
  if r[i]==r[i+1]:
    x=x+1
    if x>z:
      p=r[i]
      z=x
  else:
    x=1
for j in range(n-1):
  for i in range(n-1):
    if a[i][0]>a[i+1][0]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
    elif (a[i][1]-a[i+1][1])*p[1]<0:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
if n==1:
  print(1)
else:
  for i in range(n):
    if a[i] not in q:
      t=t+1
    q.append([a[i][0]+p[0],a[i][1]+p[1]])
    q.append([a[i][0]-p[0],a[i][1]-p[1]])
  print(t)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()

ans = 0
for i in range(n-1):
    x1, y1 = xy[i]
    for j in range(i+1, n):
        x2, y2 = xy[i+1]
        z1 = x2-x1
        z2 = y2-y1
        a = 0
        for x, y in xy:
            if [x+z1, y+z2] in xy:
                a += 1
        ans = max(ans, a)

print(n-ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

li = []

for _ in range(n):
    x, y = list(map(int, input().split(" ")))
    li.append([x, y])

li.sort()

def cal(li):
    n = len(li)
    Route = []
    for s in range(n-1):
        x1, y1 = li[s]
        route = {}
        for i in range(s+1,n):
            xi, yi = li[i]

            if xi != x1:
                diff = (yi - y1)/(xi - x1)
            else:
                diff = 10e10

            if diff in route.keys():
                route[diff].append([xi, yi])
            else:
                route[diff] = [[x1,y1], [xi, yi]]

        Route.extend(route.values())
    return Route

cost = 0
route = cal(li)

def check(A,B):
    for a in A:
        if a not in B:
            return False
    
    return True

def max_cal(route, li):
    n = len(li)
    l_max = 0
    max_li = []
    for r in route:
        if check(r,li):
            l = len(r)
            if l > l_max:
                 max_li = r
                 l_max = l
    return l_max, max_li

while True:
    l, cand = max_cal(route, li)
    if l == 0:
        cost += len(li)
        break
    else:
        route.remove(cand)
        for c in cand:
            li.remove(c)
        n -= l
        cost += 1
    if len(li) == 0:
      	break

print(cost)

Submission status: Wrong Answer

Solution code:
import statistics
import copy
import collections
n=int(input())
cnt=0
ansx=[]
ansy=[]
if n==1:
    x=list(map(int,input().split()))
    print(1)
else:
    x=[0]*n
    xx=[0]*(n-1)
    yy=[0]*(n-1)
    for i in range(n):
        x[i]=list(map(int,input().split()))
    x.sort(key=lambda x:x[1])
    x.sort(key=lambda x:x[0])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=collections.Counter(xx).most_common()
    Y=collections.Counter(yy).most_common()
    for j in range(len(X)):
        if xx.count(X[j][0])==xx.count(X[0][0]):
            for k in range(len(Y)):
                if xx.count(Y[k][0])==xx.count(Y[0][0]):
                    cnt=0
                    for i in range(n-1):
                        if xx[i]==X[j][0] and yy[i]==Y[k][0]:
                            cnt+=1
                    ansx.append(n-1-cnt+1)
                else:
                    break
        else:
            break

    x.sort(key=lambda x:x[0])
    x.sort(key=lambda x:x[1])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=collections.Counter(xx).most_common()
    Y=collections.Counter(yy).most_common()
    for j in range(len(X)):
        if xx.count(X[j][0])==xx.count(X[0][0]):
            for k in range(len(Y)):
                if xx.count(Y[k][0])==xx.count(Y[0][0]):
                    cnt=0
                    for i in range(n-1):
                        if xx[i]==X[j][0] and yy[i]==Y[k][0]:
                            cnt+=1
                    ansy.append(n-1-cnt+1)
                else:
                    break
        else:
            break
    print(min(min(ansx),min(ansy)))

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
if N<=2:
  print(1)
else:
  ans=N
  for i,j in itertools.combinations(range(N),2):
      LL=L[:]
      kans=N
      p,q=L[j][0]-L[i][0],L[j][1]-L[i][1]
      a=1 if p>=0 else -1
      b=1 if q>=0 else -1
      x,y=L[i][0],L[i][1]
      
      LL.sort(key=lambda x:(x[0]*a,x[1]*b))
      k=0
      while k<len(LL)-1 and len(LL)>=2:
        c=0
        if p==0:
          if LL[-1][0]==LL[k][0] and (LL[-1][1]-LL[k][1])%q==0 and (LL[-1][1]-LL[k][1])//q>0:
            c=1
        elif q==0:
          if LL[-1][1]==LL[k][1] and (LL[-1][0]-LL[k][0])%p==0 and (LL[-1][0]-LL[k][0])//p>0:
            c=1
        else:
          if (LL[-1][1]-LL[k][1])%q==0 and (LL[-1][0]-LL[k][0])%p==0 and (LL[-1][1]-LL[k][1])//q>0 and (LL[-1][0]-LL[k][0])//p>0:
            c=1
        if c==1:
          LL.pop()
          k=0
          kans-=1
          continue
        k+=1
        if k>=len(LL)-1:
          LL.pop()
          k=0
          continue
      ans=min(ans,kans)
  print(ans)

Submission status: Wrong Answer

Solution code:
import statistics
import copy
import collections
n=int(input())
cnt=0
ansx=[]
ansy=[]
if n==1:
    x=list(map(int,input().split()))
    print(1)
else:
    x=[0]*n
    xx=[0]*(n-1)
    yy=[0]*(n-1)
    for i in range(n):
        x[i]=list(map(int,input().split()))
    x.sort(key=lambda x:x[1])
    x.sort(key=lambda x:x[0])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=collections.Counter(xx).most_common()
    Y=collections.Counter(yy).most_common()
    for j in range(len(X)):
        if xx.count(X[j][0])==xx.count(X[0][0]):
            for k in range(len(Y)):
                if xx.count(Y[k][0])==xx.count(Y[0][0]):
                    cnt=0
                    for i in range(n-1):
                        if xx[i]==X[j][0] and yy[i]==Y[k][0]:
                            cnt+=1
                            print(1)
                    ansx.append(n-1-cnt+1)
                else:
                    break
        else:
            break

    x.sort(key=lambda x:x[0])
    x.sort(key=lambda x:x[1])
    for i in range(n-1):
        xx[i]=x[i+1][0]-x[i][0]
        yy[i]=x[i+1][1]-x[i][1]
    X=collections.Counter(xx).most_common()
    Y=collections.Counter(yy).most_common()
    for j in range(len(X)):
        if xx.count(X[j][0])==xx.count(X[0][0]):
            for k in range(len(Y)):
                if xx.count(Y[k][0])==xx.count(Y[0][0]):
                    cnt=0
                    for i in range(n-1):
                        if xx[i]==X[j][0] and yy[i]==Y[k][0]:
                            cnt+=1
                    ansy.append(n-1-cnt+1)
                else:
                    break
        else:
            break
    print(min(min(ansx),min(ansy)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
h = defaultdict(int)
for x, y in xy:
    h[(x, y)] = True
mx, my = xy[-1]
ans = 0
for i in range(n):
    x1, y1 = xy[i]
    for j in range(i+1, n):
        x2, y2 = xy[i+1]
        z1 = x2-x1
        z2 = y2-y1
        a = 0
        for x, y in xy:
            if (x+z1, y+z2) in h:
                a += 1
        ans = max(ans, a)

print(n-ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N)]
ans=N-1
def check(P,k,l,p,q):
    a,b=P[k]
    c,d=P[l]
    if p==0:
        if a==c and (b-d)%q==0:
            return True
    elif q==0:
        if b==d and (a-c)%p==0:
            return True
    else:
        if (a-c)%p==0 and (b-d)%q==0 and (a-c)//p==(b-d)//q:
            return True
    return False
for i in range(N-1):
    for j in range(i+1,N):
        cost=0
        p=P[i][0]-P[j][0]
        q=P[i][1]-P[j][1]
        used=set()
        for k in range(N):
            if k in used:
                continue
            cost+=1
            used|={k}
            for l in range(N):
                if l in used:
                    continue
                elif check(P,k,l,p,q):
                    used|={l}
    ans=min(ans,cost)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

li = []

for _ in range(n):
    x, y = list(map(int, input().split(" ")))
    li.append([x, y])

li.sort()

def cal(li):
    n = len(li)
    Route = []
    for s in range(n-1):
        x1, y1 = li[s]
        route = {}
        for i in range(s+1,n):
            xi, yi = li[i]

            if xi != x1:
                diff = (yi - y1)/(xi - x1)
            else:
                diff = 10e10

            if diff in route.keys():
                route[diff].append([xi, yi])
            else:
                route[diff] = [[x1,y1], [xi, yi]]

        Route.extend(route.values())
    return Route

cost = 0
route = cal(li)

def check(A,B):
    for a in A:
        if a not in B:
            return False
    
    return True

def max_cal(route, li):
    n = len(li)
    l_max = 0
    max_li = []
    for r in route:
        if check(r,li):
            l = len(r)
            if l > l_max:
                 max_li = r
                 l_max = l
    return l_max, max_li

while True:
    l, cand = max_cal(route, li)
    if l == 0:
        cost += len(li)
        break
    else:
        route.remove(cand)
        for c in cand:
            li.remove(c)
        n -= l
        cost += 1

print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

x = []
for _ in range(N):
  a,b = map(int,input().split())
  x.append([a,b])
  
x.sort(key=lambda x : (x[0],x[1]))

print(x)
 
y = []
for i in range(N):
  if i > 0:
    y.append((x[i][1]-x[i-1][1],x[i][0]-x[i-1][0]))

print(len(set(y)))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
li = []
if N == 1:
    a = list(map(int,input().split()))
    print(1)
    sys.exit()   

for i in range(N):
    a = list(map(int,input().split()))
    li.append(a)

cross = []

##計算量に余裕があるので全探索します
for i in range(N):
    for j in range (i+1, N):
        a = [li[j][0]-li[i][0],li[j][1]-li[i][1]]
        if a[0] < 0 and a[1] <= 0:
            b = [abs(li[j][0]-li[i][0]),abs(li[j][1]-li[i][1])]
            cross.append(b)
        elif a[0] < 0 and a[1] >= 0:
            c = li[j][1]-li[i][1]
            b = [abs(li[j][0]-li[i][0]),-c]
            cross.append(b) ####
        else:
            cross.append(a) 
lencross = len(cross)

res = 0
ans = []

for i in range (lencross):
    res = 0
    for j in range (lencross):
        if cross[i] == cross[j]:
            res += 1
    ans.append(res)
reduce = max(ans)

print(N - reduce)

Submission status: Wrong Answer

Solution code:
from itertools import count, combinations

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


N = int(input())

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

cost = float('inf')
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:
from itertools import count, combinations

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


N = int(input())

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

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=int(input())
r=[]
a=[]
for i in range(n):
  b,c=(int(j) for j in input().split())
  for k in range(i):
    d=a[k][0]-b
    e=a[k][1]-c
    if d<0:
      d=-d
      e=-e
    r.append([d,e])
  a.append([b,c])
for j in range(n-1):
  for i in range(n-1):
    if a[i][0]>a[i+1][0]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
    elif a[i][1]>a[i+1][1]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
sortsecond = lambda val: val[1]
a.sort(key=sortsecond)
r.sort()
if n>1:
  p=r[0]
x=1
z=0
t=0
q=[]
for i in range(len(r)-1):
  if r[i]==r[i+1]:
    x=x+1
    if x>z:
      p=r[i]
      z=x
  else:
    x=1
if n==1:
  print(1)
else:
  for i in range(n):
    if a[i] not in q:
      t=t+1
    q.append([a[i][0]+p[0],a[i][1]+p[1]])
    q.append([a[i][0]-p[0],a[i][1]-p[1]])
  print(t)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
a = []
b = []
if n == 1:
    print(1)
    exit()
for i in range(n):
    x, y = readmi()
    a.append([x,y])
    b.append([y,x])
a.sort()
b.sort()
aa = defaultdict(int)
bb = defaultdict(int)
old1 = 0
old2 = 0
flg = True
for i in range(n - 1):
    aa[((a[i + 1][0] - a[i][0], a[i + 1][1] - a[i][1]),1)] += 1
    bb[(b[i + 1][0] - b[i][0], b[i + 1][1] - b[i][1],i)] += 1
aaa = sorted(aa.items(), key=lambda x:x[1], reverse=True)
bbb = sorted(bb.items(), key=lambda x:x[1], reverse=True)
x = aaa[0][0][0][0]
y = aaa[0][0][0][1]
flg = False
count1 = 0
count2 = 0
for i in range(aaa[0][0][1]):
    for j in range(i, aaa[0][0][1]):
        if flg:
            if a[j][0] - x == a[i][0] and a[j][1] - y == a[i][1]:
                count1 -= 1
                flg = Flase
                break
for i in range(bbb[0][0][1]):
    for j in range(i, bbb[0][0][1]):
        if flg:
            if b[j][0] - x == b[i][0] and a[j][1] - y == a[i][1]:
                count2 -= 1
                flg = False
                break
print(max(0,min(n - (aaa[0][1] + count1), n - (bbb[0][1] - count2))))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
li = []
if N == 1:
    a = list(map(int,input().split()))
    print(1)
    sys.exit()   

for i in range(N):
    a = list(map(int,input().split()))
    li.append(a)

cross = []

##計算量に余裕があるので全探索します
for i in range(N):
    for j in range (i+1, N):
        a = [li[j][0]-li[i][0],li[j][1]-li[i][1]]
        if a[0] <= 0 and a[1] <= 0:
            b = [abs(li[j][0]-li[i][0]),abs(li[j][1]-li[i][1])]
            cross.append(b)
        elif a[0] <= 0 and a[1] >= 0:
            c = li[j][1]-li[i][1]
            b = [abs(li[j][0]-li[i][0]),-c]
            cross.append(b) ####
        else:
            cross.append(a) 
lencross = len(cross)

res = 0
ans = []

for i in range (lencross):
    res = 0
    for j in range (lencross):
        if cross[i] == cross[j]:
            res += 1
    ans.append(res)
reduce = max(ans)

print(N - reduce)

Submission status: Wrong Answer

Solution code:
n = int(input())

li = []

for _ in range(n):
    x, y = list(map(int, input().split(" ")))
    li.append([x, y])

li.sort()

def cal(li):
    n = len(li)
    Route = []
    for s in range(n-1):
        x1, y1 = li[s]
        route = {}
        for i in range(s+1,n):
            xi, yi = li[i]

            if xi != x1:
                diff = (yi - y1)/(xi - x1)
            else:
                diff = 10e10

            if diff in route.keys():
                route[diff].append([xi, yi])
            else:
                route[diff] = [[x1,y1], [xi, yi]]

        Route.extend(route.values())
    return Route

cost = 0
route = cal(li)

def check(A,B):
    for a in A:
        if a not in B:
            return False
    
    return True

def max_cal(route, li):
    n = len(li)
    l_max = 0
    max_li = []
    for r in route:
        if check(r,li):
            l = len(r)
            if l > l_max:
                 max_li = r
                 l_max = l
    return l_max, max_li

while True:
    l, cand = max_cal(route, li)
    if l == 0:
        cost += len(li)
        cost +=1
        break
    else:
        route.remove(cand)
        for c in cand:
            li.remove(c)
        n -= l
        cost += 1

print(cost)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(0,n):
    b,c=map(int,input().split())
    a.append([b,c])
d=[]
for i in range(0,len(a)-1):
    for k in range(i+1,len(a)):
        d.append([a[k][0]-a[i][0],a[k][1]-a[i][1]])
count=0
for i in range(0,len(d)):
    if d.count(d[i])>count:
        count=d.count(d[i])
print(n-count)

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
if N<=2:
  print(1)
else:
  ans=N
  for i,j in itertools.combinations(range(N),2):
      LL=L[:]
      kans=N
      p,q=L[j][0]-L[i][0],L[j][1]-L[i][1]
      a=1 if p>=0 else -1
      b=1 if q>=0 else -1
      x,y=L[i][0],L[i][1]
      
      LL.sort(key=lambda x:(x[0]*a,x[1]*b))
      k=0
      while k<len(LL)-1 and len(LL)>=2:
        c=0
        if p==0:
          if LL[-1][0]==LL[k][0] and (LL[-1][1]-LL[k][1])%q==0 and (LL[-1][1]-LL[k][1])//q>=0:
            c=1
        elif q==0:
          if LL[-1][1]==LL[k][1] and (LL[-1][0]-LL[k][0])%p==0 and (LL[-1][0]-LL[k][0])//p>=0:
            c=1
        else:
          if (LL[-1][1]-LL[k][1])%q==0 and (LL[-1][0]-LL[k][0])%p==0 and (LL[-1][1]-LL[k][1])//q>=0 and (LL[-1][0]-LL[k][0])//p>=0:
            c=1
        if c==1:
          LL.pop()
          k=0
          kans-=1
          continue
        k+=1
        if k>=len(LL)-1:
          LL.pop()
          k=0
          continue
      ans=min(ans,kans)
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
ball = [[int(i) for i in input().split()] for k in range(N)]
diff = []
if N == 1:
    print(1)
else:
    for i in range(N-1):
        for j in range(i+1, N):
            diff.append((abs(ball[i][n]-ball[j][n]) for n in range(2)))
    k = Counter(diff).most_common()[0][1]
    print(max(1,N-1-k))

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

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

common_b = 0
# def create_slope():
#     for i in range(N):
#         for j in range(i+1,N):
#             tmp = 0
#             if balls[j][0]-balls[i][0] == 0:
#                 return false, 0

#             if balls[j][0]-balls[i][0] != 0:
#                 slope = (balls[j][1]-balls[i][1]) / (balls[j][0]-balls[i][0])
#                 return true, slope


for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        if balls[j][0]-balls[i][0] != 0:
            slope = (balls[j][1]-balls[i][1]) / (balls[j][0]-balls[i][0])

            for k in range(N):
                for l in range(k+1, N):
                    if balls[k][0]-balls[l][0] == 0:
                        continue
                    
                    slope2 = (balls[k][1]-balls[l][1]) / (balls[k][0]-balls[l][0])
                    if slope == slope2 and i != k and j != k:
                        tmp+=1

        else:
            for k in range(N):
                for l in range(k+1, N):
                    if balls[k][0]-balls[l][0] == 0 and i != k and j != k:
                        tmp += 1
                        continue
                    
        common_b = max(common_b, tmp)

print(N - common_b)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import itertools
n=int(input())
xy = sorted([list(map(int,input().split())) for i in range(n)])
A = Counter([xy[i+1][0]-xy[i][0] for i in range(0,len(xy)-1)]).keys()
B = Counter([xy[i+1][1]-xy[i][1] for i in range(0,len(xy)-1)]).keys()
# A=[i for i in range(-10,10)]
# B=[i for i in range(-10,10)]
final_ans=10**9
ls = list(itertools.permutations(xy))
for a in A:
	if a==0:
		continue
	for b in B:
		if b==0:
			continue
		ans=0
		tmp0,tmp1 = xy[0]
		for i in range(1,len(xy)):
			ans += 0 if tmp0 == xy[i][0]-a  and tmp1 == xy[i][1]-b else 1
			tmp0=xy[i][0]
			tmp1=xy[i][1]
		tmp = ans
		ans=0
		tmp0,tmp1 = xy[-1]
		for i in reversed(range(1,len(xy))):
			ans += 0 if tmp0 == xy[i][0]-a and tmp1 == xy[i][1]-b else 1
			tmp0=xy[i][0]
			tmp1=xy[i][1]
		tmp_ans = min(ans,tmp)
		final_ans = min(final_ans,tmp_ans)

print(final_ans+1 if final_ans==0 else final_ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

xl = []
for i in range(n):
    x = list(map(int,input().split()))
    xl.append(x)

i = 0
pq = []
for i in range(len(xl)):
    if xl[i][0]-xl[0][0] != 0:
        p = xl[i][0]-xl[0][0]
        q = xl[i][1]-xl[0][1]
        pq += [p,q]

    elif xl[i][1]-xl[0][1] != 0:
        p = xl[i][0]-xl[0][0]
        q = xl[i][1]-xl[0][1]
        pq += [p,q]
        break
    i += 1
    
counts = []
an = []
leng = len(xl)-1
for i in range(leng+1):
    count = 0
    k = 0
    for j in range(round(len(pq)/2)):
        an = [xl[leng][0] - pq[0+k] , xl[leng][1] - pq[1+k]]
        if an in xl:
            count += 0
        else:
            count += 1
        k += 2
    counts.append(count)
    leng -= 1

ls = []
if max(counts) == 0:
    print(1)
else:
    for l in counts:
        if l != 0:
            ls.append(l)
    print(min(ls))

Submission status: Wrong Answer

Solution code:
l = input().split()
N = int(l[0])

XY = []

for i in range(N):
    l = input().split()
    XY.append((int(l[0]), int(l[1])))

# print(N, XY)

max_cost = 0
for i in range(N):
    cost_i = 0
    xy_i = XY[i]
    for j in range(N):
        cost_j = 1
        if i == j:
            continue
        xy_j = XY[j]
        diff_x = xy_i[0] - xy_j[0]
        diff_y = xy_i[1] - xy_j[1]
        # print(i, j, diff_x, diff_y)

        b_x = xy_j[0]
        b_y = xy_j[1]
        consumed = [i, j]
        while len(consumed) < N:
            found = False
            for k in range(N):
                if k in consumed:
                    continue
                d_x = b_x - XY[k][0]
                d_y = b_y - XY[k][1]
                if d_x == diff_x and d_y == diff_y:
                    # print('found chain', i, j, k)
                    cost_j += 1
                    b_x = XY[k][0]
                    b_y = XY[k][1]
                    consumed.append(k)
                    found = True
            if not found:
                break

        for l in range(N):
            if l in consumed:
                continue
            b_x = XY[l][0]
            b_y = XY[l][1]
            consumed.append(l)
            found_chain = False
            cost_l = 0
            while len(consumed) < N:
                found = False
                for k in range(N):
                    if k in consumed:
                        continue
                    d_x = b_x - XY[k][0]
                    d_y = b_y - XY[k][1]
                    if d_x == diff_x and d_y == diff_y:
                        # print('found chain', l, k, cost_l)
                        cost_l += 1
                        b_x = XY[k][0]
                        b_y = XY[k][1]
                        consumed.append(k)
                        found = True
                if not found:
                    break
            # print('cost_l', cost_l)
            if cost_l > 1:
                cost_j += cost_l - 1
        # print('cost_j', cost_j)
        cost_i = max(cost_i, cost_j)
    # print('cost_i', cost_i)
    max_cost = max(max_cost, cost_i)

print(N - max_cost)

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])
ans = 10**10
for i in range(n):
    x, y = xy[i][0], xy[i][1]
    li = []
    for j in range(n):
        xj, yj = xy[j][0], xy[j][1]
        li.append([xj-x,yj-y])
    print(li)
    a = 0
    ok = [0 for _ in range(n)]
    for k in range(n):
        if ok[k] == 0:
            a += 1
            for l in range(n-k-1):
                if l == 0:
                    ok[k+l] = 1
                elif li[k][0]==0 or li[k][1]==0:
                    continue
                elif (li[k+l][0]%li[k][0]==0) and (li[k+l][1]%li[k][1]==0):
                    ok[k+l] = 1
    ans = min(ans,a)

print(ans-1)

Submission status: Wrong Answer

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

dx = [[10**10]*N for _ in [0]*N]
dy = [[10**10]*N for _ in [0]*N]
ps = set()
qs = set()
for i in range(N):
    for j in range(N):
        if i==j:continue
        dx[i][j] = xy[i][0] - xy[j][0]
        dy[i][j] = xy[i][1] - xy[j][1]
        ps.add(dx[i][j])
        qs.add(dy[i][j])
for i in range(N):
    dx[i] = set(dx[i]) - set([10**10])
    dy[i] = set(dy[i]) - set([10**10])

ans = 0
for p in ps:
    for q in qs:
        cnt = 0
        for i in range(N):
            if (p in dx[i]) and (q in dy[i]):
                cnt += 1
        ans = max(ans,cnt)

print(N-ans)