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())

x=list()
y=list()
for i in range(n):
  xt,yt = map(int,input().split())
  x.append(xt)
  y.append(yt)
  
z=1
t=[]
for i in range(n):
  zz=0
  for j in range(n):
    if i != j:
      if x[i] == x[j]:
        zz+=1
      else:
        t.append((y[j] - y[i])/(x[j] - x[i]))
  cost = len(set(t)) + zz
  if len(t) == 0:
    cost = 1
  z=min(z,cost)
  t.clear()

print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
ls = []
B = []
ans = 0
for i in range(N):
    ls.append(list(map(int,input().split())))
for i in range(N-1):
    K = abs(((ls[i+1][0]+ls[i][0])-(ls[i+1][1]+ls[i][1])))
    B.append(K)
for i in range(N-1):
    T = min(B)
    if B[i]>T:
        ans += 1
if ans == 0:
    ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return tuple(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class UnionFind():
    def __init__(self):
        self.__table = {}
        self.__size = defaultdict(lambda: 1)

    def __root(self, x):
        if x not in self.__table:
            self.__table[x] = x
        elif x != self.__table[x]:
            self.__table[x] = self.__root(self.__table[x])

        return self.__table[x]

    def same(self, x, y):
        return self.__root(x) == self.__root(y)

    def union(self, x, y):
        x = self.__root(x)
        y = self.__root(y)
        if x != y:
            self.__size[y] += self.__size[x]
            self.__table[x] = y

    def size(self, x):
        return self.__size[self.__root(x)]

    def num_of_group(self):
        g = 0
        for k, v in self.__table.items():
            if k == v:
                g += 1
        return g


@mt
def slv(N, XY):
    c = defaultdict(list)
    for i in range(N):
        x, y = XY[i]
        for j in range(i, N):
            if i == j:
                continue
            a, b = XY[j]
            c[(x-a, y-b)].append((i, j))

    ans = 0
    for _, v in c.items():
        uf = UnionFind()
        l = set()
        r = set()

        for x, y in v:
            l.add(x)
            r.add(y)
            uf.union(x, y)

        ans = max(ans, len(l | r) - uf.num_of_group())
    return N - ans


def main():
    N = read_int()
    XY = [read_int_n() for _ in range(N)]
    print(slv(N, XY))

    # N = 50
    # XY = set()
    # while len(XY) != N:
    #     XY.add((random.randint(1, 10), random.randint(1, 10)))
    # XY = list(XY)
    # print(slv(N, XY))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
x_y_sum = [0]*n
total = []
p_q = []
for i in range(n):
    x[i], y[i] = map(int, input().split())
    x_y_sum[i] = x[i] - y[i]
    total.append([x_y_sum[i], x[i], y[i]])
total.sort()
cnt = 1
for i in range(1, n):
    p_q.append([total[i][1]-total[i-1][1], total[i][2]-total[i-1][2]])
p_q.sort()
new = []
for i in range(1, len(p_q)):
    new.append(list(set(p_q[i])-set(p_q[i-1])))
for i in range(len(new)):
    if new[i] != []:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
if N == 1:
    print("1")
else:
    L = []
    for i in range(N):
        [x, y] = map(int, input().split())
        L.append([x, y])

        #print(L)
        L.sort()
        #print(L)



    difL = []

    for i in range(N-1):
        [difx, dify] = L[i+1][0]-L[i][0], L[i+1][1]-L[i][1], 
        difL.append([difx, dify])
    #print(difL)
    t = map(tuple,difL)
    counted = collections.Counter(t)
    M = counted.most_common()[0][1]
    print(N-M)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = []
for i in range(n):
    ls.append(list(map(int,input().split())))
graph = [[0]*n for i in range(n)]
check = {}
for i in range(len(ls)):
    for j in range(1,len(ls)):
        s = str(ls[i][0]-ls[j][0]) + ',' + str(ls[i][1]-ls[j][1])
        if (s in check):
            check[s][i].append(j)
        else:
            check[s] = [[] for i in range(n)]
            check[s][i].append(j)

ans = 0


keys = list(check.keys())
for i in range(len(keys)):
    if keys[i] == '0,0':continue
    stack = []
    mh = check[keys[i]]
    check_mh = [-1]*len(mh)
    for j in range(len(mh)):
        if check_mh[j] != -1:continue
        boolian = [-1]*n
        stack.append([0,j])
        boolian[j] = 0
        check_mh[j] = 0
        while stack:
            d,v = stack.pop()
            for k in range(len(mh[v])):
                if boolian[mh[v][k]] == -1:
                    stack.append([d+1,mh[v][k]])
                    boolian[mh[v][k]] = d+1
                    check_mh[mh[v][k]] = 0
    
        check_mh[j] = max(boolian)
    ans = max(ans,sum(check_mh))

print(n-ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
xy = sorted([list(map(int, input().split())) for _ in range(N)])
diff = []
for i in range(1, len(xy)):
    x = xy[i][0]-xy[i-1][0]
    y = xy[i][1]-xy[i-1][1]
    diff.append((x,y))

c = Counter(diff)
x = 0
for i in c:
    x = max(x, c[i])

xy.sort(key=lambda x:x[1])
diff = []
for i in range(1, len(xy)):
    x = xy[i][0]-xy[i-1][0]
    y = xy[i][1]-xy[i-1][1]
    diff.append((x,y))

c = Counter(diff)
y = 0
for i in c:
    y = max(y, c[i])
m = max(x,y)
print(N-m)

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]
d = defaultdict(int)
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
        if z1 != 0 or z2 != 0:
            a = 0
            for k in range(n-1):
                z3 = xy[k+1][0]-xy[k][0]
                z4 = xy[k+1][1]-xy[k][1]
                if z1 == z3 and z2 == z4:
                    a += 1
            if ans < a:
                ans = a

print(n-ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alllist = []
minaslist = []

if N == 1:
    print("1")
else:
    for i in range(N):
        a,b = map(int,input().split())
        alllist.append([a,b])

    alllist.sort()

    for i in range(N-1):
        minaslist.append((alllist[i+1][0]-alllist[i][0] + 1)**2 - (alllist[i+1][1]-alllist[i][1] + 1)**3)



    countdict = collections.Counter(minaslist)

    lista = list(countdict.most_common())
    mostnum = lista[0][1]

    print(len(minaslist) - mostnum + 2)

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()
    mode1=list(mode1)
    saihin_kaisu=mode1[0][1]
    saihin_list=[]
    for i in range(len(mode1)):
        if mode1[i][1]==saihin_kaisu:
            saihin_list.append(mode1[i][0])

    ans=[]
    for item in saihin_list:
        xy1_diff=[]
        for i in range(0,n-1):
            if xy[i][0]-xy[i+1][0]==item:
                xy1_diff.append(xy[i][1]-xy[i+1][1])
                d=Counter(xy1_diff)
                mode2 = d.most_common(1)
                ans.append(mode2[0][1])

    print(n-max(ans))

else:
    print(1)

Submission status: Wrong Answer

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

PQ = []
# 2点を選びp,q仮決め
for i in range(N-1):
    prev = XY[i]
    for j in range(i+1,N):
        next = XY[j]
        p = next[0] - prev[0]
        q = next[1] - prev[1]
        if PQ.count([p,q]) == 0 :
            PQ.append([p,q])

ans = 10**9
# スコア計算
for p,q in PQ:
    tmp_ans = 0
    # print(f'###  (p,q) = ({p},{q})')
    for next in XY: # 次の座標
        score = 1
        # print(f'(p,q)=({p},{q})で{next}に至る最小スコア')
        for prev in XY: # 直前の座標
            if prev == next: continue
            x_ = next[0]-prev[0]
            y_ = next[1]-prev[1]
        
            if ((p==0 and x_==0 )\
                or (p>0 and x_>0 and x_%p==0)) \
                and ((q==0 and y_==0 )\
                or (q>0 and y_>0 and y_%q==0)):
                tmp_score = 0
            else:
                tmp_score = 1
            # print(f'# n:{next} p:{prev} n-p:({x_},{y_}) p:{p},q:{q} tmp:{tmp_score} score:{score}')
            score = min(score, tmp_score)
        # print(f'  => {score}')
        tmp_ans += score
    # print(f'({p},{q}) のスコア = {tmp_ans}')
    ans = min(ans, tmp_ans)
    # print(f'現在のスコア：{ans}')
print(ans)

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]
d = defaultdict(int)
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 k in range(n-1):
            z3 = xy[k+1][0]-xy[k][0]
            z4 = xy[k+1][1]-xy[k][1]
            if z1 == z3 and z2 == z4:
                a += 1
        if ans < a:
            ans = a

print(n-ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
lst = []
for i in range(n):
    lst.append(input().split())

ilst = []
for i in lst:
    i =  [ int(x) for x in i]
    ilst.append(i)
ilst.sort(reverse=True)

p = 0
q = 0
count = 0
for i in range(1, n):
    p = abs(ilst[i][0] - ilst[i-1][0])
    q = abs(ilst[i][1] - ilst[i-1][1])

    pqlst = [p, q]
    if ilst[i] == pqlst:
        count += 1
    if ilst[i][0] - ilst[i-1][0] == p and ilst[i][1] - ilst[i-1][1] == q :
        count += 0
    else:
        count += 1


print(count-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
x_y_sum = [0]*n
total = []
p_q = []
for i in range(n):
    x[i], y[i] = map(int, input().split())
    x_y_sum[i] = y[i]
    total.append([x_y_sum[i], x[i], y[i]])
total.sort()
cnt = 1
for i in range(1, n):
    p_q.append([total[i][1]-total[i-1][1], total[i][2]-total[i-1][2]])
p_q.sort()
new = []
for i in range(1, len(p_q)):
    new.append(list(set(p_q[i])-set(p_q[i-1])))
for i in range(len(new)):
    if new[i] != []:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
C = [[int(i) for i in input().split()] for i in range(N)]
pq_list = []
min_score = N
for i in range(N):
    for j in range(N):
        if(i == j):
            continue
        p = C[i][0] - C[j][0]
        q = C[i][1] - C[j][1]
        pq_list.append([p, q])

for i in range(len(pq_list)):
    score = N
    p = pq_list[i][0]
    q = pq_list[j][1]
    if(p >= 0):
        C.sort(key=lambda x: x[0], reverse=False)
    else:
        C.sort(key=lambda x: x[0], reverse=True)
    for j in range(N-1):
        for k in range(j+1, N):
            if(C[j][0] == C[k][0] + p and C[j][1] == C[k][1] + q):
                score -= 1
                break
    min_score = min(min_score, score)
    
print(min_score)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alllist = []
minaslist = []

if N == 1:
    print("1")
else:
    for i in range(N):
        a,b = map(int,input().split())
        alllist.append([a,b])

    alllist.sort()

    for i in range(N-1):
        minaslist.append((alllist[i+1][0]-alllist[i][0] + 1)**2 - (alllist[i+1][1]-alllist[i][1] + 1)**3)



    countdict = collections.Counter(minaslist)

    lista = list(countdict.most_common())
    mostnum = lista[0][1]

    print(len(minaslist) - mostnum )

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
import sys
N = int(input())
x = []
for i in range(N):
    a, b = map(int, input().split())
    x.append([a, b])
if N == 1:
    print(1)
    sys.exit()
x.sort()
cost = []
for i, y in enumerate(x):
    for j, z in enumerate(x):
        if i == j:
            continue
        else:
            a = z[0]-y[0]
            b = z[1]-y[1]
            curx = y[0]
            cury = y[1]
            num1 = 0
            for _ in range(N-1):
                curx += a
                cury += b
                if [curx, cury] in x:
                    num1 += 1
            a = z[0]-y[0]
            b = z[1]-y[1]
            a = -a
            b = -b
            curx = z[0]
            cury = z[1]
            num2 = 0
            for _ in range(N-1):
                curx += a
                cury += b
                if [curx, cury] in x:
                    num2 += 1
            cost.append(N - max(num1, num2))
print(min(cost))

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 = [abs(li[j][0]-li[i][0]),abs(li[j][1]-li[i][1])]
        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)
if N-1 < max(ans):
    reduce = N-1
else:
    reduce = max(ans)

print(N - reduce)

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]))

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

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

pre = []
ans = []
for p, q in diff:
  cost = 1
  for a, b in XY:
    if not pre:
      pre = (a, b)
      continue
    if (a - p, b - q) == pre:
      pass
    else:
      cost += 1
    pre = (a, b)
  ans.append(cost)
  pre = []
print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import collections

n = ni()

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

balls = []
dis = []

for i in range(n):
    x,y = na()
    for b in balls:
        k = '_1' if (b[0]-x)*(b[1]-y) > 0 else '_0'
        dis.append(str(abs(b[0]-x))+'_'+str(abs(b[1]-y))+k)
    balls.append([x,y])

c = collections.Counter(dis)
m = c.most_common()

print(m)

if len(m) == 1:
    print(1)
    exit()

u = m[0][1]

print(n-u)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import sys

N = int(input()) 
X_Y = [0] * N

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


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

combo = list(combinations(X_Y, 2))
diff = [0] * (len(combo))

dict_diff = {}

for i, item in enumerate(combo):
    x_dif = item[0][0] - item[1][0]
    y_dif = item[0][1] - item[1][1]
    diff[i] = [x_dif, y_dif]
    if str(diff[i]) in dict_diff:
        dict_diff[str(diff[i])] += 1
    else:
        dict_diff[str(diff[i])] = 1

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

Submission status: Wrong Answer

Solution code:
N=int(input())
x=[0]*N
y=[0]*N
a=[]
b=[]
c=[]
for i in range(N):
  x[i], y[i]=map(int, input().split())
  
for n in range(1,N):
  a.append(x[n]-x[n-1])
  b.append(y[n]-y[n-1])

a.sort()
b.sort()
d=0
for m in range(N-1):
  if d!=0:
    if a[m]!=a[m-1] or b[m]!=b[m-1]:
      c.append(d)
      d=0
  d=d+1

print(1 if c==[] else 1+N-len(c))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#N, K = map(int, input().split(" "))

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

	gess = {}
	xm = 0
	ym = 0

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

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess:
			gess[(p, q)] += 1
		else:
			gess[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess, key=gess.get)
	nai = gess[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(x[0]))
	gess1 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess1:
			gess1[(p, q)] += 1
		else:
			gess1[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess1, key=gess1.get)
	nai1 = gess1[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(-x[0]))
	gess2 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess2:
			gess2[(p, q)] += 1
		else:
			gess2[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess2, key=gess2.get)
	nai2 = gess2[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(x[1]))
	gess3 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess3:
			gess3[(p, q)] += 1
		else:
			gess3[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess3, key=gess3.get)
	nai3 = gess3[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(-x[1]))
	gess4 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess4:
			gess4[(p, q)] += 1
		else:
			gess4[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess4, key=gess4.get)
	nai4 = gess4[(p,q)]

	#########
	xy = sorted(xy, key=lambda x:(x[0],-x[1]))
	gess5 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess5:
			gess5[(p, q)] += 1
		else:
			gess5[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess5, key=gess5.get)
	nai5 = gess5[(p,q)]

	#########
	random.shuffle(xy)
	gess6 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess6:
			gess6[(p, q)] += 1
		else:
			gess6[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess6, key=gess6.get)
	nai6 = gess6[(p,q)]

	#########
	random.shuffle(xy)
	gess7 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess7:
			gess7[(p, q)] += 1
		else:
			gess7[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess7, key=gess7.get)
	nai7 = gess7[(p,q)]
		#########
	random.shuffle(xy)
	gess8 = {}
	xm = 0
	ym = 0

	for i, val in enumerate(xy):
		if i == 0:
			x,y = val
			xm = x
			ym = y
			continue
		x, y = val

		p = x - xm
		q = y - ym
		if (p,q) in gess8:
			gess8[(p, q)] += 1
		else:
			gess8[(p, q)] = 1
		xm = x
		ym = y

	p, q = max(gess8, key=gess8.get)
	nai8 = gess8[(p,q)]

	tmp = max(nai, nai2, nai3,nai4, nai5,nai6,nai1,nai7,nai8)

	print(N-tmp)



if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
x_y_sum = [0]*n
total = []
p_q = []
for i in range(n):
    x[i], y[i] = map(int, input().split())
    x_y_sum[i] = x[i]
    total.append([x_y_sum[i], x[i], y[i]])
total.sort()
cnt = 1
for i in range(1, n):
    p_q.append([total[i][1]-total[i-1][1], total[i][2]-total[i-1][2]])
p_q.sort()
new = []
for i in range(1, len(p_q)):
    new.append(list(set(p_q[i])-set(p_q[i-1])))
for i in range(len(new)):
    if new[i] != []:
        cnt += 1
print(cnt)

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 = 100
for l in list(itertools.permutations(balls)):
    dic = {}
    px = l[0][0]
    py = l[0][1]
    t_max = 0
    for i in range(1,len(l)):
        dx = l[i][0] - px
        px = l[i][0]
        dy = l[i][1] - py
        py = l[i][1]
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1
            if (t_max < dic[(dx,dy)]):
                t_max = dic[(dx,dy)]
        kitai = + N - i
        if ans < (N - kitai):
            break
    d_max = t_max
    cost = N - d_max
    if (cost < ans):
        ans = cost
        if (ans == 1):
            print(ans)
            exit()

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
lst = []
for i in range(n):
    lst.append(input().split())

ilst = []
for i in lst:
    i =  [ int(x) for x in i]
    ilst.append(i)
ilst.sort(reverse=True)
print(ilst)
p = 0
q = 0
count = 0
for i in range(1, n):
    p = abs(ilst[i][0] - ilst[i-1][0])
    q = abs(ilst[i][1] - ilst[i-1][1])

    pqlst = [p, q]
    if ilst[i] == pqlst:
        count += 1
    if ilst[i][0] - ilst[i-1][0] == p and ilst[i][1] - ilst[i-1][1] == q :
        count += 0
    else:
        count += 1


print(count-1)

Submission status: Wrong Answer

Solution code:
import statistics
import copy
import collections
n=int(input())
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],reverse=True)
    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()[0][0]
    Y=collections.Counter(yy).most_common()[0][0]
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    ansx0=max(cntx,cnty)

    x.sort(key=lambda x:x[0],reverse=True)
    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()[0][0]
    Y=collections.Counter(yy).most_common()[0][0]
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    ansy0=max(cntx,cnty)

    x.sort(key=lambda x:x[1])
    x.sort(key=lambda x:x[0],reverse=True)
    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()[0][0]
    Y=collections.Counter(yy).most_common()[0][0]
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    ansx1=max(cntx,cnty)

    x.sort(key=lambda x:x[0])
    x.sort(key=lambda x:x[1],reverse=True)
    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()[0][0]
    Y=collections.Counter(yy).most_common()[0][0]
    cntx=n-1-xx.count(X)+1
    cnty=n-1-yy.count(Y)+1
    ansy1=max(cntx,cnty)
    print(min(ansx0,ansy0,ansx1,ansy1))

Submission status: Wrong Answer

Solution code:

def calc(XYi, pq):
    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():
        if i == 0 and pq:
            continue
        v = dictX[i]
        if v > maxv:
            maxv = v
            p = i

    maxv = 0
    for i in dictY.keys():
        if i == 0 and not pq:
            continue
        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 = min(calc(XYi, True), calc(XYi, False))


print(costX)

Submission status: Wrong Answer

Solution code:
N = int(input())
ls = []
B = []
ans = 1
for i in range(N):
    ls.append(list(map(int,input().split())))
for i in range(N-1):
    K = abs(((ls[i+1][0]+ls[i+1][1])-(ls[i][0]+ls[i][1])))
    B.append(K)
for i in range(N-1):
    T = min(B)
    if B[i]>T:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import itertools

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

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

ptn=list(itertools.combinations(xy,2))
pq=[]
for idx,val in enumerate(ptn):
        if val[1][0]-val[0][0] <= 0 and val[1][1]-val[0][1] <= 0:
                pq.append(str(abs(val[1][0]-val[0][0])) + 'x' + str(abs(val[1][1]-val[0][1])))
        else:
                pq.append(str(val[1][0]-val[0][0]) + 'x' + str(val[1][1]-val[0][1]))

cpq = Counter(pq)

# pqans=cpq.most_common(1)[0][0]
redsc=cpq.most_common(1)[0][1]

# p,q = map(int,pqans.split('x'))
print(N-redsc)

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=n
ma=0

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        che=0
        p=x[j]-x[i]
        q=y[j]-y[i]

        for c in range(n-1):
            for d in range(c+1,n): 
                if x[c]==x[d]-p and y[c]==y[d]-q:
                    che=che+1
        ma=max(ma,che)

print(cost-ma)