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 = [[int(i) for i in input().split()] for i in range(N)]

#xy = list(map(list, set(map(tuple, xy))))

d = {}
m = 0
for i in range(N):
    for j in range(i+1, N):
        a, b = xy[i][0]-xy[j][0], xy[i][1]-xy[j][1]
        if a < 0 and b < 0:
            a = abs(a)
            b = abs(b)
        if (a, b) in d:
            d[a, b] += 1
        else:
            d[a, b] = 1

for val in d.values():
    m = max(m, val)
#print(d)
print(N-m)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from operator import sub

def main():
    N = int(input())
    balls = [tuple(map(int,input().split())) for _ in range(N)]
    d = defaultdict(int)
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            d[tuple(map(sub, balls[i], balls[j]))] += 1
    try:
        print(N-max(d.values()))
    except:
        print(100)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if n!=1:
    xy0_diff=[]
    for i in range(0,n-1):
        xy0_diff.append(xy[i][0]-xy[i+1][0])

    c=Counter(xy0_diff)
    mode1 = c.most_common(1)
    saihin=mode1[0][0]

    xy1_diff=[]
    for i in range(0,n-1):
        if xy[i][0]-xy[i+1][0]==saihin:
            xy1_diff.append(xy[i][1]-xy[i+1][1])

    d=Counter(xy1_diff)
    mode2 = d.most_common(1)
    kaisu=mode2[0][1]

    print(n-kaisu)

else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort(key = lambda x: (-x[0], -x[1]))

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

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

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###
import collections

N = int(input())
XYs = [tuple(mi()) for _ in range(N)]

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

sa_list = []
import itertools
for (ax, ay), (bx, by) in itertools.combinations(XYs, 2):
  sa_list.append((ax-bx,ay-by) if ax-bx>=0 else (-(ax-bx),-(ay-by)))

#最も多い差の個数（これ-1を短縮できるはず）
#print(N-collections.Counter(sa_list).most_common()[0][1])

#最も多い差をタプルで受ける
mostcommon = collections.Counter(sa_list).most_common()[0][0]
#print(mostcommon)

#print(sa_list)
cnt = 0
ans = N #ここから引いていく
#aとbの差がmostcommonと一致したらvisitedに入れる
for a in range(0, N):
  tmpsame = 0 #今見ているaと差が同じものの数
  for b in range(0, N):
    if a>=b: continue
    sa = sa_list[cnt]
    if sa == mostcommon:
#      print('same')
      ans -= 1
    cnt += 1
#    print(sa)

if len(sa_list)>=2:
  #次に多い差をタプルで受ける
  mostcommon = collections.Counter(sa_list).most_common()[1][0]
  cnt = 0
  ans2 = N #ここから引いていく
  #aとbの差がmostcommonと一致したらvisitedに入れる
  for a in range(0, N):
    tmpsame = 0 #今見ているaと差が同じものの数
    for b in range(0, N):
      if a>=b: continue
      sa = sa_list[cnt]
      if sa == mostcommon:
        ans2 -= 1
      cnt += 1
  print(min(ans, ans2))
else:
  print(ans)

Submission status: Wrong Answer

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


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

PQ=set()

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

        u,v=x2-x1,y2-y1

        PQ.add((u,v))

def find(x):#find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):  # xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))
ANS=50

for p,q in PQ:

    Group=[i for i in range(N)]#グループ分け.Group[i]=jのときiとjは同じグループ

    for i in range(N-1):
        for j in range(i+1,N):
            if B[i][0]+p==B[j][0] and B[i][1]+q==B[j][1]:
                Union(i,j)
            if B[i][0]-p==B[j][0] and B[i][1]-q==B[j][1]:
                Union(i,j)

    G2=[find(i) for i in range(N)]
    ANS=min(ANS,len(set(G2)))

print(ANS)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
c = Counter((y[0] - x[0], y[1] - x[1]) for i, x in enumerate(a) for y in a[:i])
print(n - max(c.values(), default=0))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
x = [0] * N
y = [0] * N
ans = N

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

for i in range(N):
  cost = N
  for j in range(N):
    p = x[i] - x[j]
    q = y[i] - y[j]
    diffx = np.diff(x)
    diffy = np.diff(y)
    for k in range(N-1):
      if diffx[k] == p and diffy[k] == q:
        cost = cost -1 
  ans = min(ans,cost)

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
sa = {}
for i in itertools.combinations(xy, 2):
    a, b = i
    c = ",".join([str(b[0] - a[0]), str(b[1] - a[1])])
    if c not in sa:
        sa[c] = 1
    else:
        sa[c] += 1
ans = 0
for i in sa.values():
    ans = max(ans, i)
print(n - ans)

Submission status: Wrong Answer

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

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


diff = []
for tmp in range(n-1):
    diff.append(
        [xy[tmp][0] - xy[tmp+1][0], xy[tmp][1] - xy[tmp+1][1]]
        )

ans = get_unique_list(diff)


print(len(ans))

Submission status: Wrong Answer

Solution code:
import collections
import itertools

N = int(input())

x, y = [], []

for i in range(N):
    xx, yy = list(map(int, input().split()))
    x.append(xx)
    y.append(yy)

l = []

if N == 1:
    print(1)
else:
    for c in itertools.combinations(range(N), 2):
        x1 = x[c[0]]
        y1 = y[c[0]]
        x2 = x[c[1]]
        y2 = y[c[1]]

        l.append((abs(x1-x2), abs(y1-y2)))

    c = collections.Counter(l)
    p = c.most_common()[0][0]
    pp = c.most_common()[0][1]

    aa = []

    for c in itertools.combinations(range(N), 2):
        x1 = x[c[0]]
        y1 = y[c[0]]
        x2 = x[c[1]]
        y2 = y[c[1]] 

        if (abs(x1-x2), abs(y1-y2)) == p:
            aa.append(c)

    assert(len(aa) == pp)

    ll = [0] * N
    curG = 0
    for i in range(pp):
        if (ll[aa[i][0]] != 0):
            ll[aa[i][1]] = ll[aa[i][0]]
        elif (ll[aa[i][1]] != 0):
            ll[aa[i][0]] = ll[aa[i][1]]
        else:
            curG += 1
            ll[aa[i][0]] = curG
            ll[aa[i][1]] = curG

    k = 1 if 0 in ll else 0

    ccc = len(set(ll)) - k

    z = ll.count(0)

    inter = (N - z) - ccc

    print(N-inter)

Submission status: Wrong Answer

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

ret = 0
pq = []

for i in range(N) :        
    for j in range(i+1, N) :
        p = xy[j][0] - xy[i][0]
        q = xy[j][1] - xy[i][1]
        pq.append((p, q))
        
pq = list(set(pq))

ret = float('inf')
for p, q in pq :
    tmp = 0
    visited = [0] * N
    for i in range(N) :
        if visited[i] :
            continue
        
        if p == 0 :
            for j in range(N) :
                if visited[j] :
                    continue
                if xy[j][0] == xy[i][0] :
                    visited[j] = 1
        
        elif q == 0 :
            for j in range(N) :
                if visited[j] :
                    continue
                if xy[j][1] == xy[i][1] :
                    visited[j] = 1
                    
        else :
            for j in range(N) :
                if visited[j] :
                    continue
                dx = xy[j][0] - xy[i][0]
                dy = xy[j][1] - xy[i][1]
                if dx % p == 0 and dy % q == 0 and dx // p == dy // q:
                    visited[j] = 1
                    
        tmp += 1
        
    ret = min(tmp, ret)
    
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())


def solve():

    initial_cost = 1

    # (x,y) list
    xy_list = []
    for i in range(N):
        x, y = map(int, input().split())
        xy_list.append((x, y))
    xy_list_sorted = sorted(xy_list, key=lambda a: a[0])

    if N == 1 or N == 2:
        return 1

    xy_sub_dic = {}
    xy_sub_dic2 = {}
    for i in range(N):
        for j in range(i+1, N):
            xs = xy_list_sorted[j][0] - xy_list_sorted[i][0]
            ys = xy_list_sorted[j][1] - xy_list_sorted[i][1]
            if xy_sub_dic.get((xs, ys)) is None:
                xy_sub_dic[(xs, ys)] = 1
            else:
                xy_sub_dic[(xs, ys)] += 1

            xs2 = xy_list_sorted[i][0] - xy_list_sorted[j][0]
            ys2 = xy_list_sorted[i][1] - xy_list_sorted[j][1]
            if xy_sub_dic2.get((xs2, ys2)) is None:
                xy_sub_dic2[(xs2, ys2)] = 1
            else:
                xy_sub_dic2[(xs2, ys2)] += 1

    xy_sub_dic_sorted = sorted(xy_sub_dic.items(), key=lambda a: a[1], reverse=True)
    xy_sub_dic_sorted2 = sorted(xy_sub_dic2.items(), key=lambda a: a[1], reverse=True)

    return initial_cost + (N - 1) - max(xy_sub_dic_sorted[0][1], xy_sub_dic_sorted2[0][1])
print(solve())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [list(map(int,input().split())) for _ in range(N)]
A = []
p, q = 0, 0

for i in range(N-1):
    for j in range(i+1,N):
        p = L[j][0] - L[i][0]
        q = L[j][1] - L[i][1]
        if p*q != 0:
            if p*q > 0 and p < 0:
                A.append([-1*p,-1*q])
            else:
                A.append([p,q])

A.sort()
S = []
ctr = 0
for k in range(len(A)-1):
    for l in range(k+1, len(A)):
        if A[k] == A[l]:
            ctr += 1
        else:
            S.append(ctr)
            ctr = 0

if len(S) == 0:
    n = 0
elif max(S) == 0:
    n = 0
else:
    n = max(S) + 1

print( (N-n+1)//2 )

Submission status: Wrong Answer

Solution code:
def calc(XYi):
    dictX = {}
    dictY = {}
    for i in range(N - 1):
        x, y = XYi[i][0], XYi[i][1]
        nx, ny = XYi[i + 1][0], XYi[i + 1][1]
        tx = x - nx
        ty = y - ny

        vx = dictX.get(tx)
        vy = dictY.get(ty)

        if vx:
            dictX[tx] = vx + 1
        else:
            dictX[tx] = 1
        if vy:
            dictY[ty] = vy + 1
        else:
            dictY[ty] = 1

    p = 0
    q = 0
    maxv = 0
    for i in dictX.keys():
        v = dictX[i]
        if v > maxv:
            maxv = v
            p = i

    maxv = 0
    for i in dictY.keys():
        v = dictY[i]
        if v > maxv:
            maxv = v
            q = i

    cost = 1
    for i in range(N - 1):
        x, y = XYi[i][0], XYi[i][1]
        nx, ny = XYi[i + 1][0], XYi[i + 1][1]
        tx = x - nx
        ty = y - ny
        if tx == p and ty == q:
            pass
        else:
            cost += 1
    return cost


N = int(input())
XYi = [0] * N
for i in range(N):
    x, y = list(map(int, input().split()))
    XYi[i] = (x, y)

for i in range(N):
    for k in range(N):
        if i < k:
            if XYi[i][0] > XYi[k][0]:
                t = XYi[i]
                XYi[i] = XYi[k]
                XYi[k] = t
            elif XYi[i][0] == XYi[k][0]:
                if XYi[i][1] > XYi[k][1]:
                    t = XYi[i]
                    XYi[i] = XYi[k]
                    XYi[k] = t
costX = calc(XYi)

for i in range(N):
    for k in range(N):
        if i < k:
            if XYi[i][1] > XYi[k][1]:
                t = XYi[i]
                XYi[i] = XYi[k]
                XYi[k] = t
            elif XYi[i][1] == XYi[k][1]:
                if XYi[i][0] > XYi[k][0]:
                    t = XYi[i]
                    XYi[i] = XYi[k]
                    XYi[k] = t
costY = calc(XYi)
print(min(costX, costY))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ball = [0] * N

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

ans = N

# p,q の組
for i in range(N) :
    for j in range(N) :
        p = ball[j][0] - ball[i][0]
        q = ball[j][1] - ball[i][1]

        if p == 0 and q == 0 :
            continue

        group = []

        if p == 0 : # y = b
            for k in range(N) : # xがゼロ以下になるまで引き，切片を求める
                mul = math.ceil(ball[k][1] / q)
                b = ball[k][1] - q * mul
                x = ball[k][0]
                group.append((x,b))
        else :
            for k in range(N) :
                mul = math.ceil(ball[k][0] / p) # 引く回数
                b = ball[k][1] - q * mul
                x = ball[k][0] - p * mul
                group.append((x,b))
        count = set(group)
        ans = min(ans,len(count))

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

N=int(input())
xlist=[]
ylist=[]
for i in range(N):
  x, y = map(int, stdin.readline().rstrip().split())
  xlist.append(x)
  ylist.append(y)

tupleList=[]
for i in range(N):
  for j in range(N):
    if i != j:
      tupleList.append((xlist[i] - xlist[j], ylist[i] - ylist[j]))

#c = collections.Counter(tupleList)
#print(N-max(c.values()))

Submission status: Wrong Answer

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

if N == 0:
    print(0)

from collections import Counter
r = 0
XY.sort(key=lambda x:x[0])
XY.sort(key=lambda x:x[1])
for i in range(N - 1):
    zmm = []
    for j in range(i, N-1):
        t = XY[j] if j==i else XY[j+1]
        a = t[0] - XY[j+1][0]
        b = t[1] - XY[j+1][1]
        zmm.append((a, b))
    r = max(Counter(zmm).most_common(1)[0][1], r)

print(r)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict

def read_input():
    n = int(input())

    points = []
    for i in range(n):
        points.append(tuple(map(int, input().split())))

    return n, points


# calc p3 is on line made by p1 and p2
def check_on_line(p1, p2, p3):
    a = (p2[0] - p1[0], p2[1] - p1[1])
    b = (p3[0] - p1[0], p3[1] - p1[1])

    axb = a[0]*b[1] - a[1]*b[0]

    # on line
    if axb == 0:
        return True
    return False


def dist_point_to_point(p1, p2):
    return (p2[0] - p1[0], p2[1] - p1[1])


def submit():
    n, points = read_input()

    if n == 1:
        print(1)
        return

    p2p_dist = {}
    pd_list = defaultdict(list)
    for p1 in points:
        for p2 in points:
            if p1 == p2:
                continue
            p2p_dist[(p1, p2)] = dist_point_to_point(p1, p2)

            for p3 in points:
                if check_on_line(p1, p2, p3):
                    pd_list[(p1, p2p_dist[(p1, p2)])].append(p3)

    pq_list = list(set(p2p_dist.values()))

    min_line_c = 51
    for p, q in pq_list:
        line_c = 0
        point_c = 0
        used = {}
        for s in points:
            used[s] = False

        # print(p, q)
        for s in points:
            if used[s]:
                continue
            lines = pd_list[(s, (p, q))]

            if lines:
                for pl in lines:
                    used[pl] = True
                    point_c += 1
            else:
                used[s] = True
                point_c += 1

            line_c += 1
            # print(used, line_c)

            if point_c == n:
                break

        if min_line_c > line_c:
            min_line_c = line_c

    print(min_line_c)

if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
INF = 10 ** 100
n = int(raw_input())
ns = []

for i in xrange(n):
    (y, x) = map(int, raw_input().split())
    ns.append((y, x))

ns.sort()

ans = INF

if n == 1:
    ans = 0

for i in xrange(n):
    for j in xrange(i + 1, n):
        dy, dx = ns[j][0] - ns[i][0], ns[j][1] - ns[i][1]

        ps = ns[:]
        st = set(ps)
        cnt = 0

        for p in ps:
            y, x = p
            if (y, x) not in st:
                continue
            st.remove((y, x))
            cnt += 1
            while True:
                ny, nx = y + dy, x + dx
                if (ny, nx) not in st:
                    break
                st.remove((ny, nx))
                y, x = ny, nx
        ans = min(ans, cnt)

print ans

Submission status: Wrong Answer

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

cost = 0
for i in range(N):
    link = []
    for j in range(N):
        if i == j:
            continue
        dx = abs(x[i] - x[j])
        dy = abs(y[i] - y[j])

        link.append([dx, dy])
    c = 0
    for k in link:
        v = 0
        for l in link:
            if l == k or (k[0] == l[0] and k[1] == l[0]):
                v += 1
        c = max(c, v)        
    cost = max(cost, c)

print(N - cost)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

n = ni()
li = []
li2 = []
for i in range(n):
    x, y = na()
    li.append([x,y])
    li2.append((i,x*x+y*y))
li2.sort(key=lambda x:(x[1],x[0]))
ct = 1
dif = []
for i in range(n-1):
    mae = li[li2[i][0]]
    tugi = li[li2[i+1][0]]
    dx = tugi[0] - mae[0]
    dy = tugi[1] - mae[1]
    dif.append([dx, dy])
print(len(get_unique_list(dif)))

Submission status: Wrong Answer

Solution code:
def calc(XYi):
    dictX = {}
    dictY = {}
    for i in range(N - 1):
        x, y = XYi[i][0], XYi[i][1]
        nx, ny = XYi[i + 1][0], XYi[i + 1][1]
        tx = x - nx
        ty = y - ny

        vx = dictX.get(tx)
        vy = dictY.get(ty)

        if vx:
            dictX[tx] = vx + 1
        else:
            dictX[tx] = 1
        if vy:
            dictY[ty] = vy + 1
        else:
            dictY[ty] = 1

    p = 0
    q = 0
    maxv = 0
    for i in dictX.keys():
        v = dictX[i]
        if v > maxv:
            maxv = v
            p = i

    maxv = 0
    for i in dictY.keys():
        v = dictY[i]
        if v > maxv:
            maxv = v
            q = i

    cost = 1
    for i in range(N - 1):
        x, y = XYi[i][0], XYi[i][1]
        nx, ny = XYi[i + 1][0], XYi[i + 1][1]
        tx = x - nx
        ty = y - ny
        if tx == p and ty == q:
            pass
        else:
            cost += 1
    return cost


N = int(input())
XYi = [0] * N
for i in range(N):
    x, y = list(map(int, input().split()))
    XYi[i] = (x, y)

for i in range(N):
    for k in range(N):
        if i < k:
            if XYi[i][0] > XYi[k][0]:
                t = XYi[i]
                XYi[i] = XYi[k]
                XYi[k] = t
            elif XYi[i][0] == XYi[k][0]:
                if XYi[i][1] > XYi[k][1]:
                    t = XYi[i]
                    XYi[i] = XYi[k]
                    XYi[k] = t
costX = calc(XYi)

for i in range(N):
    for k in range(N):
        if i < k:
            if XYi[i][1] > XYi[k][1]:
                t = XYi[i]
                XYi[i] = XYi[k]
                XYi[k] = t
            elif XYi[i][1] == XYi[k][1]:
                if XYi[i][0] > XYi[k][0]:
                    t = XYi[i]
                    XYi[i] = XYi[k]
                    XYi[k] = t
costY = calc(XYi)
print(max(costX, costY))

Submission status: Wrong Answer

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


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

PQ=set()

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

        u,v=x2-x1,y2-y1

        PQ.add((u,v))

def find(x):#find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):  # xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))
ANS=50

for p,q in PQ:

    Group=[i for i in range(N)]#グループ分け.Group[i]=jのときiとjは同じグループ

    for i in range(N-1):
        for j in range(i+1,N):
            if B[i][0]+p==B[j][0] and B[i][1]+q==B[j][1]:
                Union(i,j)

    G2=[find(i) for i in range(N)]
    ANS=min(ANS,len(set(G2)))

print(ANS)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

ans_list = []
for pat in list(itertools.permutations(balls)):
    dic = {}
    l = list(pat)
    px = l[0][0]
    py = l[0][1]
    for i in range(len(l)):
        dx = l[i][0] - px
        dy = l[i][1] - py
        px = l[i][0]
        py = l[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())
    ans_list.append(N - d_max)

print(min(ans_list))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
s=[]
l.sort(key=lambda x:x[0],reverse=True)
ans=0
flag=False
for i in range(n-1,0,-1):
    val=(l[i][0]-l[i-1][0],l[i][1]-l[i-1][1])
    if(flag and val==s[-1]):
        s.append(val)
        ans+=1
    if(not flag):
        ans=1
        s.append(val)
        flag=True
print(ans)

Submission status: Wrong Answer

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def mod_inv(x):
    # available only when mod is prime
    global mod
    return pow(x, mod - 2, mod)


def gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    n = intin()
    xylist = intinl(n)

    pqtoij = defaultdict(list)

    for i in range(n):
        for j in range(i + 1, n):
            x1, y1 = xylist[i]
            x2, y2 = xylist[j]

            if x1 - x2 >= 0:
                p = x1 - x2
                q = y1 - y2
            else:
                p = -(x1 - x2)
                q = -(y1 - y2)

            pqtoij[(p, q)].append((i, j))

    maxcount = 0

    for (p, q), ijlist in pqtoij.items():
        checked = []
        count = 0
        for i, j in ijlist:
            if (i, j) in checked:
                continue
            count += 1
            checked.append((i, j))
        maxcount = max(maxcount, count)

    print(n - maxcount)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
s=[]
l.sort(key=lambda x:x[0],reverse=True)
ans=0
flag=False
for i in range(n-1,0,-1):
    val=(l[i][0]-l[i-1][0]),abs(l[i][1]-l[i-1][1])
    if(flag and val==s[-1]):
        s.append(val)
        ans+=1
    if(not flag):
        ans=1
        s.append(val)
        flag=True
print(ans)

Submission status: Wrong Answer

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

import copy

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

result = float('inf')

for i in range(N):
    for j in range(N-i-1):
        p = List[i+j+1][0] - List[i][0]
        q = List[i+j+1][1] - List[i][1]
        tmp_list = copy.deepcopy(List)
        cost = 0
        
        for k in range(N):
            if [tmp_list[0][0] + p, tmp_list[0][1] + q] in List:
                tmp_cost = 0
            else:
                tmp_cost = 1
            cost += tmp_cost
            del tmp_list[0]
        if result > cost:
            result = cost
                    
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
if N==1:
    print(1)
else:
    nums = []
    costs = []
    xup =[]
    yup =[]
    ans = 1
    for i in range(N):
        x,y = map(int,input().split())
        nums.append((x,y))
    nums.sort(key=lambda  x:(x[0],x[1]))
    for i in range(1,len(nums)):
        xup.append(nums[i][0]-nums[i-1][0])
        yup.append(nums[i][1] - nums[i-1][1])
    values,counts = zip(*Counter(xup).most_common())
    newxups = []
    maxx = max(counts)
    for value,counts in zip(values,counts):
        if counts==maxx:
            newxups.append(value)
    newyups = []
    values,counts = zip(*Counter(yup).most_common())
    maxy = max(counts)
    for value,counts in zip(values,counts):
        if counts==maxy:
            newyups.append(value)
    newyup = Counter(yup).most_common()[0][0]
    newxup = Counter(xup).most_common()[0][0]
    ans = 1
    anss = []
    for xup in newxups:
        ans=1
        for yup in newyups:
            for i in range(1,len(nums)):
                if nums[i][0] - xup != nums[i - 1][0] or nums[i][1] - yup != nums[i - 1][1]:
                    ans += 1
        anss.append(ans)
    print(min(anss))

Submission status: Wrong Answer

Solution code:
import sys
from itertools import combinations

def main():
    input = sys.stdin.readline
    N = int(input())
    cord = []
    for _ in range(N):
        x, y = map(int, input().split())
        cord.append((x, y))

    ans = 50
    for a in combinations(cord, 2):
        x1, y1 = a[0]
        x2, y2 = a[1]

        X = set()
        Y = set()
        for x, y in cord:
            X.add(x)
            Y.add(y)
            
        ans = min(ans, len(X), len(Y))

        if x1 != x2 and y1 != y2:
            p = x2 - x1
            q = y2 - y1

            b = set()
            for x, y  in cord:
                b.add(y * p  - q  * x)

            ans = min(ans, len(b))

    return ans


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