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:
from collections import defaultdict

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

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

d = defaultdict(int)
max_count = 0
max_f = None
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = points[i]
        xj, yj = points[j]
        if xi == xj and yi == yj:
            continue
        if xi < xj:
            key = (xj - xi, yj - yi)
        elif xj < xi:
            key = (xi - xj, yi - yj)
        elif xi == xj:
            key = (0, float('inf'))
        elif yi == yj:
            key = (float('inf'), 0)
        d[key] += 1
        if d[key] > max_count:
            max_count = d[key]
            max_f = key


class UnionFind(object):

    def __init__(self, N):
        self.tree = [i for i in range(N)]
        self.rank = [0] * (N + 1)

    def find(self, x):
        if self.tree[x] == x:
            return x
        else:
            self.tree[x] = self.find(self.tree[x])  # 経路圧縮
            return self.tree[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        # ランクを考慮しない場合はどちらが親になっても良い
        if self.rank[x] < self.rank[y]:
            self.tree[x] = y
        else:
            self.tree[y] = x

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def has_same_parent(self, x, y):
        return self.find(x) == self.find(y)


p, q = max_f
uf = UnionFind(N)
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = points[i]
        xj, yj = points[j]
        if (p == 0 and xi == xj) or (q == 0 and yi == yj):
            uf.unite(i, j)
        else:
            if p == 0 or q == 0:
                continue
            elif (xj - xi == p and yj - yi == q) or (xi - xj == p and yi - yj == q):
                uf.unite(i, j)

print(len(set(uf.tree)))

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from collections import defaultdict

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

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

d = defaultdict(int)
max_count = 0
max_f = None
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = points[i]
        xj, yj = points[j]
        if xi == xj and yi == yj:
            continue
        if xi < xj:
            key = (xj - xi, yj - yi)
        elif xj < xi:
            key = (xi - xj, yi - yj)
        elif xi == xj:
            key = (0, float('inf'))
        elif yi == yj:
            key = (float('inf'), 0)
        d[key] += 1
        if d[key] > max_count:
            max_count = d[key]
            max_f = key


class UnionFind(object):

    def __init__(self, N):
        self.tree = [i for i in range(N)]
        self.rank = [0] * (N + 1)

    def find(self, x):
        if self.tree[x] == x:
            return x
        else:
            self.tree[x] = self.find(self.tree[x])  # 経路圧縮
            return self.tree[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        # ランクを考慮しない場合はどちらが親になっても良い
        if self.rank[x] < self.rank[y]:
            self.tree[x] = y
        else:
            self.tree[y] = x

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def has_same_parent(self, x, y):
        return self.find(x) == self.find(y)


p, q = max_f
uf = UnionFind(N)
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = points[i]
        xj, yj = points[j]
        if (p == 0 and xi == xj) or (q == 0 and yi == yj):
            uf.unite(i, j)
        else:
            if p == 0 or q == 0:
                continue
            elif ((xj - xi) / p).is_integer() and ((yj - yi) / q).is_integer():
                uf.unite(i, j)

print(len(set(uf.tree)))

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from collections import defaultdict

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

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

d = defaultdict(set)
for i in range(N):
    for j in range(N):
        xi, yi = points[i]
        xj, yj = points[j]
        if xi == xj or yi == yj:
            continue
        f = Fraction(xj - xi, yj - yi)
        d[f].add(i)
        d[f].add(j)

g = list(d.values())
seen = set()
cnt = 0
while len(seen) < N:
    g.sort(key=lambda s: len(s) - len(s & seen), reverse=True)
    seen.update(g[0])
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from collections import defaultdict

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

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

d = defaultdict(set)
for i in range(N):
    for j in range(N):
        xi, yi = points[i]
        xj, yj = points[j]
        if xi == xj or yi == yj:
            continue
        f = Fraction(xj - xi, yj - yi)
        d[f].add(i)
        d[f].add(j)

g = list(d.values())
seen = set()
cnt = 0
while len(seen) < N:
    g.sort(key=lambda s: len(s & seen))
    seen.update(g[0])
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


N = int(input())
xy = {}
for i in range(N):
  x, y = map(int, input().split())
  xy[i] = (x, y)
  
ret = float("inf")  

# 2点選んで傾きを決める
index = [i for i in range(N)]
for i, j in combinations(index, 2):
  x1, y1 = xy[i]
  x2, y2 = xy[j]

  if x1 == x2:
    diff_x = 0
    diff_y = min(abs(y1 - y2), abs(y2 - y1))
  else:
    if y1 == y2:
      diff_x = min(abs(x1 - x2), abs(x2 - x1))
      diff_y = 0
    else:
      diff_x = x1 - x2
      diff_y = y1 - y2
  
  # 傾きの条件を満たす直線上の点をチェックしていく
  nocheck = [1 for k in range(N)]
  tmp_ret = 0
  for k in range(N):
    if nocheck[k]:
      tmp_ret += 1 
      nocheck[k] = 0
      x, y = xy[k]
      
      for l in range(N):
        if nocheck[l]:
          _x, _y = xy[l]
          if diff_x == 0 and x == _x:
            if y > _y:
              if (y - _y) % diff_y == 0:
                nocheck[l] = 0
            else:
              if (_y - y) % diff_y == 0:
                nocheck[l] = 0
          elif diff_y == 0 and y == _y:
            if x > _x:
              if (x - _x) % diff_x == 0:
                nocheck[l] = 0
            else:
              if (_x - x) % diff_x == 0:
                nocheck[l] = 0    
          else:
            if diff_x * (y - _y) == diff_y * (x - _x):
              nocheck[l] = 0
    if sum(nocheck) == 0:
      break
      
  ret = min(ret, tmp_ret)
  
print(ret)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


N = int(input())
xy = {}
for i in range(N):
  x, y = map(int, input().split())
  xy[i] = (x, y)
  
ret = float("inf")  

# 2点選んで傾きを決める
index = [i for i in range(N)]
for i, j in combinations(index, 2):
  x1, y1 = xy[i]
  x2, y2 = xy[j]

  diff_x = x1 - x2
  diff_y = y1 - y2
  
  # 傾きの条件を満たす直線上の点をチェックしていく
  nocheck = [1 for k in range(N)]
  tmp_ret = 0
  for k in range(N):
    if nocheck[k]:
      tmp_ret += 1 
      nocheck[k] = 0
      x, y = xy[k]
      
      for l in range(N):
        if nocheck[l]:
          _x, _y = xy[l]
          if diff_x == 0 and x == _x:
            if y > _y:
              if (y - _y) % diff_y == 0:
                nocheck[l] = 0
            else:
              if (_y - y) % diff_y == 0:
                nocheck[l] = 0
          elif diff_y == 0 and y == _y:
            if x > _x:
              if (x - _x) % diff_x == 0:
                nocheck[l] = 0
            else:
              if (_x - x) % diff_x == 0:
                nocheck[l] = 0    
          else:
            if diff_x * (y - _y) == diff_y * (x - _x):
              nocheck[l] = 0
    if sum(nocheck) == 0:
      break
      
  ret = min(ret, tmp_ret)
  
print(ret)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


N = int(input())
xy = {}
for i in range(N):
  x, y = map(int, input().split())
  xy[i] = (x, y)
  
ret = float("inf")  

# 2点選んで傾きを決める
index = [i for i in range(N)]
for i, j in combinations(index, 2):
  x1, y1 = xy[i]
  x2, y2 = xy[j]

  diff_x = x1 - x2
  diff_y = y1 - y2
  
  # p, q は同時には 0 ではない
  if diff_x == 0 and diff_y == 0:
    continue
  
  # 傾きの条件を満たす直線上の点をチェックしていく
  nocheck = [1 for k in range(N)]
  tmp_ret = 0
  for k in range(N):
    if nocheck[k]:
      tmp_ret += 1 
      nocheck[k] = 0
      x, y = xy[k]
      
      for l in range(N):
        if nocheck[l]:
          _x, _y = xy[l]
          if diff_x * (y - _y) == diff_y * (x - _x):
            nocheck[l] = 0
    if sum(nocheck) == 0:
      break
      
  ret = min(ret, tmp_ret)
  
print(ret)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


N = int(input())
xy = {}
for i in range(N):
  x, y = map(int, input().split())
  xy[i] = (x, y)
  
ret = float("inf")  

# 2点選んで傾きを決める
index = [i for i in range(N)]
for i, j in combinations(index, 2):
  x1, y1 = xy[i]
  x2, y2 = xy[j]

  diff_x = x1 - x2
  diff_y = y1 - y2
  
  # p, q は 0 ではない
  if diff_x == 0 or diff_y == 0:
    continue
  
  # 傾きの条件を満たす直線上の点をチェックしていく
  nocheck = [1 for k in range(N)]
  tmp_ret = 0
  for k in range(N):
    if nocheck[k]:
      tmp_ret += 1 
      nocheck[k] = 0
      x, y = xy[k]
      
      for l in range(N):
        if nocheck[l]:
          _x, _y = xy[l]
          if diff_x * (y - _y) == diff_y * (x - _x):
            nocheck[l] = 0
    if sum(nocheck) == 0:
      break
      
  ret = min(ret, tmp_ret)
  
print(ret)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


N = int(input())
xy = {}
for i in range(N):
  x, y = map(int, input().split())
  xy[i] = (x, y)
  
ret = float("inf")  

index = [i for i in range(N)]
for i, j in combinations(index, 2):
  x1, y1 = xy[i]
  x2, y2 = xy[j]

  diff_x = x1 - x2
  diff_y = y1 - y2
  
  nocheck = [1 for k in range(N)]
  tmp_ret = 0
  for k in range(N):
    if nocheck[k]:
      tmp_ret += 1 
      nocheck[k] = 0
      x, y = xy[k]
      for l in range(N):
        if nocheck[l]:
          _x, _y = xy[l]
          if diff_x == 0:
            if y - _y == diff_y or _y - y == diff_y:
              nocheck[l] = 0
          elif diff_y == 0:
            if x - _x == diff_x or _x - x == diff_x:
              nocheck[l] = 0
          elif diff_x * (y - _y) == diff_y * (x - _x):
            nocheck[l] = 0
    if sum(nocheck) == 0:
      break
      
  ret = min(ret, tmp_ret)
  
print(ret)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


N = int(input())
xy = {}
for i in range(N):
  x, y = map(int, input().split())
  xy[i] = (x, y)
  
ret = float("inf")  

index = [i for i in range(N)]
for i, j in combinations(index, 2):
  x1, y1 = xy[i]
  x2, y2 = xy[j]

  diff_x = x1 - x2
  diff_y = y1 - y2
  
  nocheck = [1 for k in range(N)]
  tmp_ret = 0
  for k in range(N):
    if nocheck[k]:
      tmp_ret += 1 
      nocheck[k] = 0
      x, y = xy[k]
      for l in range(N):
        if nocheck[l]:
          _x, _y = xy[l]
          if diff_x * (y - _y) == diff_y * (x - _x):
            nocheck[l] = 0
    if sum(nocheck) == 0:
      break
      
  ret = min(ret, tmp_ret)
  
print(ret)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction,gcd
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
lst=[]
for i in range(N):
    for m in range(i+1,N):
        x1,y1=XY[i]
        x2,y2=XY[m]
        A=x1-x2
        B=y1-y2
        if not A or not B:
            if not [A,B] in lst:
                lst.append([A,B])
        else:
            Z=gcd(A,B)
            A//=Z
            B//=Z
            if not [A,B] in lst:
                lst.append([A,B])

num=50
for A,B in lst:

    count=N
    idx=set()
    for i in range(N):
        for m in range(i+1,N):
            if m in idx:
                continue
            x1,y1=XY[i]
            x2,y2=XY[m]
            if not A:
                if x1==x2:

                    idx.add(m)
                    count-=1

            elif not B:
                if y1==y2:
                    idx.add(m)
                    count-=1
            elif (x1-x2)//A==(y1-y2)//B:
                idx.add(m)
                count-=1
    num=min(num,count)

print(num)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
lst=set()
for i in range(N):
    for m in range(i+1,N):
        x1,y1=XY[i]
        x2,y2=XY[m]
        if not x1-x2:
            pass
        elif not y1-y2:
            pass
        else:
            lst.add(Fraction(y1-y2)/(x1-x2))

num=50
#print(lst)
for A in lst:
    siki=set()
    for x,y in XY:
        if A=="tate":
            B=x
        else:
            B=y-A*x
        siki.add(B)

    #print(siki)
    num=min(num,len(siki))
print(num)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
lst=set()
for i in range(N):
    for m in range(i+1,N):
        x1,y1=XY[i]
        x2,y2=XY[m]
        if not x1-x2:
            lst.add("tate")
        elif not y1-y2:
            lst.add(0)
        else:
            lst.add(Fraction(y1-y2)/(x1-x2))

num=50
#print(lst)
for A in lst:
    siki=set()
    for x,y in XY:
        if A=="tate":
            B=x
        else:
            B=y-A*x
        siki.add(B)

    #print(siki)
    num=min(num,len(siki))
print(num)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
lst=set()
for i in range(N):
    for m in range(i+1,N):
        x1,y1=XY[i]
        x2,y2=XY[m]
        if not (x1-x2):
            lst.add(0)
        elif not y1-y2:
            lst.add("tate")
        else:
            lst.add(Fraction(y1-y2)/(x1-x2))

num=50
for A in lst:
    siki=set()
    for x,y in XY:
        if A=="tate":
            B=x
        else:
            B=y-A*x
        siki.add(B)

    #print(siki)
    num=min(num,len(siki))
print(num)

Submission status: Wrong Answer

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
d=[]
for i in range(n):
    for j in range(n):
        if i!=j:
            d.append([xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]])
d.sort()
res = 1
tres = 1
for i in range(len(d)-1):
    if d[i] == d[i+1]:
        tres += 1
    else:
        tres = 1
    res = max(res,tres)
print(n-res)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

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

m = {}
for i in range(N):
    for j in range(i, N):
        if i != j:
            x, y = L[i]
            x2, y2 = L[j]

            key = (x - x2, y - y2)

            if m.get(key) == None:
                m[key] = 0
            m[key] += 1

if m == {}:
    print(1)
    exit()
print(N - max(m.values()))

Submission status: Wrong Answer

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

check = [0] * N
answer = 0

while 1:
  max_set = [(0, 0), (0, 0), 0]
  for i in range(N):
    if check[i]:
      continue
    xi, yi = xy[i][0], xy[i][1]
    for j in range(i + 1, N):
      if check[j]:
        continue
      xj, yj = xy[j][0], xy[j][1]
      dx, dy = xj - xi, yj - yi
      cnt = 2
      for k in range(1, N + 1):
        if [xj + k * dx, yj + k * dy] in xy:
          cnt += 1
        else:
          break
      if max_set[2] < cnt:
        max_set = [(xi, yi), (dx, dy), cnt]
  #print(max_set)
  if max_set[2] == 0:
    break
  
  x, y = max_set[0]
  dx, dy = max_set[1]
  for i in range(max_set[2]):
    id = xy.index([x + i * dx, y + i * dy])
    check[id] = 1
  answer += 1
  
print(answer)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N=int(input())
xy=[list(map(int,input().split())) for i in range(N)]
xy.sort()
inf=float("inf")
ans=inf
for i in range(N-1):
    for j in range(i+1,N):
        p=xy[j][0]-xy[i][0]
        q=xy[j][1]-xy[i][1]
        flag=[0]*N
        cnt=0
        for k in range(N):
            if flag[k]==0:
                flag[k]=1
                cnt+=1
                nx,ny=xy[k][0]+p,xy[k][1]+q
                b=bisect_left(xy,[nx,ny])
                while b<N and xy[b]==[nx,ny]:
                    flag[b]=1
                    nx,ny=nx+p,ny+q
                    b=bisect_left(xy,[nx,ny])
        ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b


from itertools import combinations
from collections import defaultdict, Counter

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

if N == 1:
    print(1)
    exit()
cnts = defaultdict(lambda: 0)
dxy = []
for pa, pb in combinations(points, 2):
    dx = pa[0] - pb[0]
    dy = pa[1] - pb[1]
    # if dx < 0:
    # dx *= -1
    # dy *= -1
    dxy.append((dx, dy))
    # cnts[(dx, dy)] += 1

print(N - max(Counter(dxy).values()))

# print(N - max(cnts.values()))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b


from itertools import combinations
from collections import defaultdict, Counter

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

if N == 1:
    print(1)
    exit()
# cnts = defaultdict(lambda: 0)
dxy = []
for pa, pb in combinations(points, 2):
    dx = pa[0] - pb[0]
    dy = pa[1] - pb[1]
    if dx < 0:
        dx *= -1
        dy *= -1
    dxy.append((dx, dy))
    # cnts[(dx, dy)] += 1

print(N - max(Counter(dxy).values()))

# print(N - max(cnts.values()))

Submission status: Wrong Answer

Solution code:
#各操作でコストゼロになるボールは一意
n = int(input())
x = []
y = []
for i in range(n):
    xi,yi =map(int, input().split( ))
    x.append(xi)
    y.append(yi)

cnt = {}

for i in range(n):
    for j in range(i):
        d1 = x[i]-x[j]
        d2 = y[i]-y[j]
        if (d1,d2) in cnt:
            cnt[(d1,d2)] += 1
        else:
            cnt[(d1,d2)] = 1

tmp = 0

for k in cnt:
    tmp = max(tmp, cnt[k])

print(n-tmp)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

SIZE = 10 ** 10

A.sort(key = lambda x: x[1])
A.sort()
#print("A", *A)

counter = defaultdict(int)
for x, y in A:
  a = x * SIZE + y
  counter[a] += 1
#print(counter)

answer = 0
for i in range(N):
  xi = A[i][0]
  yi = A[i][1]
  xyi = xi * SIZE + yi
  if counter[xyi]:
    max_i = [0, 0, 1, -1]
    for j in range(i + 1, N):
      xj = A[j][0]
      yj = A[j][1]
      xyj = xj * SIZE + yj
      if counter[xyj]:
        cnt = 1
        dx = xj - xi
        dy = yj - yi
        for k in range(1, N):
          xk = dx * k + xi
          yk = dy * k + yi
          ic = xk * SIZE + yk
          if counter[ic]:
            cnt += 1
          else:
            break
        if max_i[2] < cnt:
          max_i = [dx, dy, cnt, j]
    
    #print(max_i)
    max_cnt = max_i[2]
    if max_cnt == 1:
      counter[xyi] = 0
      answer += 1
    else:
      max_dx = max_i[0]
      max_dy = max_i[1]
      for l in range(max_cnt):
        xl = xi + max_dx * l
        yl = yi + max_dy * l
        xyl = xl * SIZE + yl
        counter[xyl] = 0
      answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

def cost(p,q):
    e = 0
    for i in range(n):
        for j in range(n):
            v = xy[i]
            u = xy[j]
            if p==u[0]-v[0] and q==u[1]-v[1]:
                e += 1
                break
    return n-e

res = 10**9
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        v = xy[i]
        u = xy[j]
        res = min(res, cost(v[0]-u[0], v[1]-u[1]))

print(res)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def sol(XY):
  XYdif = []
  for i in range(N-1):
    XYdif.append([XY[i+1][0]-XY[i][0],XY[i+1][1]-XY[i][1]])

  XYcnt = {}
  for xdif,ydif in XYdif:
    if xdif == 0 and ydif == 0: continue
    tmp_key = str(xdif) + '-' + str(ydif) 
    if tmp_key in XYcnt:
      XYcnt[tmp_key] += 1
    else:
      XYcnt[tmp_key] = 1
  
  if len(XYcnt) == 0:
    return N
  
  max_XYcnt = -float('inf')
  for key, num in XYcnt.items():
    max_XYcnt = max(max_XYcnt, num)

  return (N-max_XYcnt)

N = int(input())
if N == 1:
  print(1)
  exit()
  
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort()
ans1 = sol(XY)
XY.sort(key=itemgetter(1))
ans2 = sol(XY)
XY.sort(reverse=True)
ans3 = sol(XY)
XY.sort(key=itemgetter(1),reverse=True)
ans4 = sol(XY)
print(min([ans1,ans2,ans3,ans4]))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def sol(XY):
  XYdif = []
  for i in range(N-1):
    XYdif.append([XY[i+1][0]-XY[i][0],XY[i+1][1]-XY[i][1]])

  XYcnt = {}
  for xdif,ydif in XYdif:
    if xdif == 0 and ydif == 0: continue
    tmp_key = str(xdif) + '-' + str(ydif) 
    if tmp_key in XYcnt:
      XYcnt[tmp_key] += 1
    else:
      XYcnt[tmp_key] = 1
  
  if len(XYcnt) == 0:
    return N
  
  max_XYcnt = -float('inf')
  for key, num in XYcnt.items():
    max_XYcnt = max(max_XYcnt, num)

  return (N-max_XYcnt)

N = int(input())
if N == 1:
  print(1)
  exit()
  
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort()
ans1 = sol(XY)
XY.sort(key=itemgetter(1))
ans2 = sol(XY)
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def sol(XY):
  XYdif = []
  for i in range(N-1):
    XYdif.append([XY[i+1][0]-XY[i][0],XY[i+1][1]-XY[i][1]])

  XYcnt = {}
  for xdif,ydif in XYdif:
    if xdif == 0 or ydif == 0: continue
    tmp_key = str(xdif) + '-' + str(ydif) 
    if tmp_key in XYcnt:
      XYcnt[tmp_key] += 1
    else:
      XYcnt[tmp_key] = 1
  
  if len(XYcnt) == 0:
    return N
  
  max_XYcnt = -float('inf')
  for key, num in XYcnt.items():
    max_XYcnt = max(max_XYcnt, num)

  return (N-max_XYcnt)

N = int(input())
if N == 1:
  print(1)
  exit()
  
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort()
ans1 = sol(XY)
XY.sort(key=itemgetter(1))
ans2 = sol(XY)
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def sol(XY):
  XYdif = []
  for i in range(N-1):
    XYdif.append([XY[i+1][0]-XY[i][0],XY[i+1][1]-XY[i][1]])

  XYcnt = {}
  for xdif,ydif in XYdif:
    tmp_key = str(xdif) + '-' + str(ydif) 
    if tmp_key in XYcnt:
      XYcnt[tmp_key] += 1
    else:
      XYcnt[tmp_key] = 1
    
  max_XYcnt = -float('inf')
  for key, num in XYcnt.items():
    max_XYcnt = max(max_XYcnt, num)

  return (N-max_XYcnt)

N = int(input())
if N == 1:
  print(1)
  exit()
  
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort()
ans1 = sol(XY)
XY.sort(key=itemgetter(1))
ans2 = sol(XY)
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def sol(XY):
  XYdif = []
  for i in range(N-1):
    XYdif.append([XY[i+1][0]-XY[i][0],XY[i+1][1]-XY[i][1]])

  XYcnt = {}
  for xdif,ydif in XYdif:
    tmp_key = str(xdif) + '-' + str(ydif) 
    if tmp_key in XYcnt:
      XYcnt[tmp_key] += 1
    else:
      XYcnt[tmp_key] = 1
    
  max_XYcnt = -float('inf')
  for key, num in XYcnt.items():
    max_XYcnt = max(max_XYcnt, num)

  return (N-max_XYcnt)

N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort()
ans1 = sol(XY)
XY.sort(key=itemgetter(1))
ans2 = sol(XY)
print(min(ans1,ans2))

Submission status: Wrong Answer

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

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

XYcnt = {}
for xdif,ydif in XYdif:
  tmp_key = str(xdif) + '-' + str(ydif) 
  if tmp_key in XYcnt:
    XYcnt[tmp_key] += 1
  else:
    XYcnt[tmp_key] = 1
    
max_XYcnt = -float('inf')
for key, num in XYcnt.items():
  max_XYcnt = max(max_XYcnt, num)

print(N-max_XYcnt)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import defaultdict


def main():
    N = int(input())
    if N == 1:
        print(1)

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

        dd = defaultdict(int)

        for xy1, xy2 in itertools.combinations(XY, 2):
            a = (xy2[0] - xy1[0], xy2[1] - xy1[1])
            dd[a] += 1

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


main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():
    N = int(input())
    if N == 1:
        print(1)

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

        dd = defaultdict(int)
        for i in range(N - 1):
            for j in range(i + 1, N):
                a = (XY[j][0] - XY[i][0], XY[j][1] - XY[i][1])
                dd[a] += 1

        pq = max(dd, key=dd.get)

        cnt = 0
        for x, y in XY:
            if [x - pq[0], y - pq[1]] in XY:
                cnt += 1

        print(N - cnt)


main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():
    N = int(input())
    if N == 1:
        print(1)

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

        dd = defaultdict(int)
        for i in range(N - 1):
            for j in range(i + 1, N):
                a = (XY[j][0] - XY[i][0], XY[j][1] - XY[i][1])
                dd[a] += 1

        print(dd)
        pq = max(dd, key=dd.get)

        cnt = 0
        for x, y in XY:
            if [x - pq[0], y - pq[1]] in XY:
                cnt += 1

        print(N - cnt)


main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():
    N = int(input())
    if N == 1:
        print(1)

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

        dd = defaultdict(int)
        for i in range(N - 1):
            for j in range(i + 1, N):
                a = (XY[j][0] - XY[i][0], XY[j][1] - XY[i][1])
                dd[a] += 1

        pq = max(dd, key=dd.get)

        cnt = 0
        for x, y in XY:
            if [x + pq[0], y + pq[1]] in XY:
                cnt += 1

        print(N - cnt)


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
xy.sort()

ans = 10**9
for i in range(n - 1):
    xi, yi = xy[i]
    for j in range(i + 1, n):
        xj, yj = xy[j]
        p = xj - xi
        q = yj - yi
        if p == 0 or q == 0:
            continue

        tmp = n-1
        for k in range(n):
            if k == i or k == j:
                continue
            xk, yk = xy[k]
            ppp = xk - xi
            qqq = yk - yi
            if ppp % p == 0 and qqq % q == 0 and ppp // p == qqq // q:
                tmp -= 1
        ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())

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

ans = 10**10

for i in range(N):
    for j in range(N):

        if i==j:
            continue

        p = B[i][0]-B[j][0]
        q = B[i][1]-B[j][1]
        uf = UnionFind(N)

        for k in range(N):
            for l in range(N):

                if k==l:
                    continue

                if B[k][0]-B[l][0] == p and B[k][1]-B[l][1] == q:
                    uf.union(k,l)

        ans = min(ans,uf.group_count())

print(ans if N != 1 else 0)

Submission status: Wrong Answer

Solution code:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())

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

ans = 10**10

for i in range(N):
    for j in range(N):
        
        if i==j:
            continue
            
        p = B[i][0]-B[j][0]
        q = B[i][1]-B[j][1]
        uf = UnionFind(N)
        
        for k in range(N):
            for l in range(N):
                
                if k==l:
                    continue
                    
                if B[k][0]-B[l][0] == p and B[k][1]-B[l][1] == q:
                    uf.union(k,l)
                    
        ans = min(ans,uf.group_count())

print(ans)