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 Counter
import sys

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

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

dc_c = []
dc_c = []
dc_ans = []
for i in range(n-1):
    ii = 0
    d = [[-1]*2 for i in range(n-1)]
    for j in range(i,n):
        if i != j:
            d[ii][0] = abs(x[i]-x[j])
            d[ii][1] = abs(y[i]-y[j])
            ii += 1
    dc = Counter(map(tuple, d))
    dc_ans = Counter(dc_ans) + dc
dc_ans = dc_ans.most_common()
if dc_ans[0][0] == (-1, -1):
    print(n-dc_ans[1][1])
else:
    print(n-dc_ans[0][1])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
if N == 1:
    print("1")
elif N == 2:
    print("1")
else:
    L = []
    for i in range(N):
        [x, y] = map(int, input().split())
        L.append([x, y])
        L.sort()
        
    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])

    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())
XY = [list(map(int,input().split())) for _ in range(N)]
def gdb(a,b):
    a,b = abs(a),abs(b)
    while b:
        a,b = b,a%b
    return a
def make_slope(a,b):
    if a==0:
        print("error")
    elif a>0:
        return(a//gdb(a,b),b//gdb(a,b))
    elif a<0:
        return(-1*a//gdb(a,b),-1*b//gdb(a,b))


slope_list = []
for i in range(1,N):
    for j in range(i):
        x1,y1 = XY[i]
        x2,y2 = XY[j]
        d_x = x2-x1
        d_y = y2-y1
        if d_x != 0:
            d_x,d_y = make_slope(d_x,d_y)
            if not([d_x,d_y] in slope_list):
                slope_list.append([d_x,d_y])

if N <= 2:
    print(1)
else:
    tmp = []
    for x,y in XY:
        if not (x in tmp):
            tmp.append(x)
    ans = len(tmp)

    for d_x,d_y in slope_list:
        XY_list = []
        for x1,y1 in XY:
            if XY_list == []:
                XY_list.append([x1,y1])
            else:
                for x2,y2 in XY_list:
                    d_x_tmp = x2-x1
                    d_y_tmp = y2-y1
                    if d_x_tmp == 0:
                        break
                    d_x_tmp,d_y_tmp = make_slope(d_x_tmp,d_y_tmp)
                    if d_x_tmp==d_x and d_y_tmp==d_y:
                        break
                else:
                    XY_list.append([x1,y1])
        ans = min(ans,len(XY_list))
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, x: "List[int]", y: "List[int]"):
    rem = {}
    for i in range(N):
        for j in range(i + 1, N):
            if x[i] < x[j]:
                dx = x[j] - x[i]
                dy = y[j] - y[i]
            else:
                dx = x[i] - x[j]
                dy = y[i] - y[j]


            found = False
            for dx2, dy2  in rem.keys():
                if dx * dy2 == dy * dx2:
                    rem[(dx2, dy2)].add(j)
                    found = True
            if not found:
                rem[(dx, dy)] = set()
                rem[(dx, dy)].add(j)
  
    dd = 0
    if 0 < len(rem):
        dd = max([len(v) for k, v in rem.items()])
    return N - dd


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    result = solve(N, x, y)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
sa = []
for i in range(n):
    for j in range(n):
        if i != j:
            sa.append([xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]])

ans = 10 ** 15
for p, q in sa:
    tmp = 1
    for i in range(1, n):
        a = xy[i][0] - xy[i - 1][0]
        b = xy[i][1] - xy[i - 1][1]
        if p != a or q != b:
            tmp += 1
    ans = min(ans, tmp)

xy.sort(key=lambda x:x[1])
for p, q in sa:
    tmp = 1
    for i in range(1, n):
        a = xy[i][0] - xy[i - 1][0]
        b = xy[i][1] - xy[i - 1][1]
        if p != a or q != b:
            tmp += 1
    ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:

def gcd(a, b):
    if b < 0:
        return gcd(a, -b)
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def solve():
    N = int(raw_input())
    xy = [None] * N
    for i in range(N):
        xi, yi = [int(_) for _ in raw_input().split()]
        xy[i] = (xi, yi)
    xy.sort(key = lambda x: x[0])
    pq_set = []
    def AddToPQSet(ele):
        pq, i, j = ele
        # if len(pq_set) == 0 or pq_set[0][0] > pq:
        #     pq_set.insert(0, (pq, set()))
        #     pq_set[0][1].add(i)
        #     pq_set[0][1].add(j)
        added_flag = False
        for ind in range(0, len(pq_set)):
            if pq_set[ind][0] == pq:
                subset_added = False
                for subset in pq_set[ind][1]:
                    if i in subset:
                        subset.add(j)
                        subset_added = True
                        break
                    elif j in subset:
                        subset.add(i)
                        subset_added = True
                        break
                if not subset_added:
                    tmp_set = set()
                    tmp_set.add(i)
                    tmp_set.add(j)
                    pq_set[ind][1].append(tmp_set)
                added_flag = True
                break
            elif pq_set[ind][0] > pq:
                tmp_set = set()
                tmp_set.add(i)
                tmp_set.add(j)
                pq_set.insert(ind, (pq, [tmp_set]))
                added_flag = True
                break
        if not added_flag:
            tmp_set = set()
            tmp_set.add(i)
            tmp_set.add(j)
            pq_set.append((pq, [tmp_set]))
        # print pq
        # print "i = " + str(i) + ", j = " + str(j)
        # print pq_set

    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]
            _gcd = gcd(p,q)
            # print "i = " + str(i) + ", j = " + str(j)
            # print p, q, _gcd
            p = p / _gcd
            q = q / _gcd
            AddToPQSet(((p,q),i,j))

    maxcntpq = 0
    # print pq_set
    for i in range(len(pq_set)):
        num_subset = len(pq_set[i][1])
        cnt = - num_subset
        for subset in pq_set[i][1]:
            cnt += len(subset)
        if cnt > maxcntpq:
            maxcntpq = cnt
    print N - maxcntpq

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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

cross = []

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

res = 0
ans = []

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

print(N - reduce)

Submission status: Wrong Answer

Solution code:
import itertools
import collections

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

cma = {}
tmp = list(itertools.combinations(range(len(Z)), 2))
for s, t in tmp:
    hop = ((Z[t][1] - Z[s][1]) , (Z[t][0] - Z[s][0]))
    if hop[0] <= 0 and hop[1] <= 0:
        hop = (hop[0] * -1, hop[1] * -1)
    cma.setdefault(str(hop[0]) + "." + str(hop[1]), 0)
    cma[str(hop[0]) + "." + str(hop[1])] += 1

if cma != {}:
    cma_sorted = sorted(cma.items(), key=lambda x:x[1])
    print(N - cma_sorted[-1][1])
else:
    print(N)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict

n = int(input())
patterns = defaultdict(int)

last_x, last_y = map(int, input().split())
for _ in range(1, n):
    x, y = map(int, input().split())
    diff_x = x - last_x
    diff_y = y - last_y
    last_x, last_y = x, y
    pattern = '{0}, {1}'.format(diff_x, diff_y)
    patterns[pattern] += 1

if n > 1:
    ans = n - max(patterns.values())
else:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
print(arr)
ans=n
for i in range(n):
  for j in range(i+1,n):
    p,q=arr[j][0]-arr[i][0],arr[j][1]-arr[i][1]
    cnt=0
    flag=[0]*n
    for k in range(n):
      if flag[k]==1:
        continue
      flag[k]=1
      a,b=arr[k][0],arr[k][1]
      while 1:
        for l in range(n):
          if flag[l]==1:
            continue
          if a+p==arr[l][0] and b+q==arr[l][1]:
            flag[l]=1
            a=arr[l][0]
            b=arr[l][1]
            break
        else:
          break
      cnt+=1
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = []

for i in range(N):
    x, y = map(int, input().split(" "))
    XY.append((x, y))

val_max = 10 ** 9

Div_list = []

for i in range(N):
    x_i, y_i = XY[i]
    for j in range(i+1, N):
        x_j, y_j = XY[j]
        Div_list.append((abs(x_i - x_j), abs(y_i - y_j)))


Div_list_sorted = sorted(Div_list)

Div_list_len = len(Div_list_sorted)

Div_list_result = []

count_max = 0
if Div_list_len == 1:
    count_max = 1
else:

    skip = 0

    for i in range(Div_list_len):
        count = 1
        if skip > 0:
            skip -= 1
            continue

        s_i = Div_list_sorted[i]
        if s_i[0] == 0 or s_i[1] == 0:
            continue

        for j in range(i+1, Div_list_len):
            s_j = Div_list_sorted[j]

            if s_i == s_j:
                count += 1

        skip = (count - 1)

        Div_list_result.append(count+1)

Div_list_result_sorted = sorted(Div_list_result, reverse=True)
count_max = N
ans = 0
i = 0
Div_list_result_length = len(Div_list_result_sorted)
while 0 < count_max and i < Div_list_result_length:
    count_max -= Div_list_result_sorted[i]
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())

if n==1:
    a,b=(map(int, input().split()))
    print(1)
else:

    arr=[]
    for i in range(n):
        a,b=(map(int, input().split()))
        arr.append([a,b])

    tmparr=[]
    for num in range(len(arr)-1):
        for nn,i in enumerate(arr[num+1:]):
            
            tmparr.append(((arr[num][0]-i[0]),(arr[num][1]-i[1])))
            #print(tmparr)
        #print(tmparr)
    #print(set(tmparr))
    c = collections.Counter(tmparr)
    print(n-c.most_common()[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    xy = [list(map(int, input().split())) for _ in range(n)]
    ans = float('inf')

    for first in range(n):
        for second in range(n):
            if first != second:
                p = xy[first][0] - xy[second][0]
                q = xy[first][1] - xy[second][1]

                for pi, qi in zip([p, -p], [q, -q]):
                    prev_a = xy[first][0]
                    prev_b = xy[first][1]
                    count = 0

                    for i in range(n):
                        if i != first:
                            if (xy[i][0] - pi) != prev_a or (xy[i][1] - qi) != prev_b:
                                count += 1

                            prev_a = xy[i][0]
                            prev_b = xy[i][1]

                    ans = min(ans, count)

                    prev_a = xy[second][0]
                    prev_b = xy[second][1]
                    count = 0

                    for i in range(n):
                        if i != second:
                            if (xy[i][0] - pi) != prev_a or (xy[i][1] - qi) != prev_b:
                                count += 1

                            prev_a = xy[i][0]
                            prev_b = xy[i][1]

                    ans = min(ans, count)
    print(ans + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# -*- coding: utf-8 -*-
import sys
import numpy as np
# 行数
N = int(input().strip())

# 2次元配列
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

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

Result=N-2
#print ("Result is" + str(Result))

#print(grid)
for a in range(N):
    #Re_t=1
    A = [grid[a][0],grid[a][1]]
    #print ("A equal")
    #print (A)
    for b in range(N):
        if a == b:
            continue
        B = [grid[b][0],grid[b][1]]
        #print ("A equal " + str(A) + " B equal " + str(B))
        #print (B)
        if (B[0]-A[0]) == 0:
        	k = 0
        else:
        	k = (B[1]-A[1])/(B[0]-A[0])
        #print ("katamuki is" + str(k))
        Re_t=1
        #print (k)
        for c in range(N):
            if (a == c) or (b == c):
                continue
            C = [grid[c][0],grid[c][1]]
            if (B[0]-A[0]) == 0:
                cy = B[1]
            else:
                cy = B[1] + ((B[1]-A[1])*(C[0]-B[0]))/(B[0]-A[0])
            if cy == C[1]:
                #print("ack")
                continue
            else:
                #print("out")
                Re_t = Re_t + 1
            if int(Result) < int(Re_t) - 1:
                #print("out")
                break #
        #print ("result_tmp is" + str(Re_t))
        if Result > Re_t:
            Result = Re_t
            #print ("result is overritten")
            #print (Result)
                
#print("end")
print (Result)

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)**4)



    countdict = collections.Counter(minaslist)

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

    print(len(minaslist) - mostnum + 1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, x: "List[int]", y: "List[int]"):
    rem = {}
    for i in range(N):
        for j in range(i + 1, N):
            dx = x[i] - x[j]
            dy = y[i] - y[j]

            found = False
            for dx2, dy2  in rem.keys():
                if dx * dy2 == dy * dx2:
                    rem[(dx2, dy2)].add(j)
                    found = True
            if not found:
                rem[(dx, dy)] = set()
                rem[(dx, dy)].add(j)
  
    dd = 0
    if 0 < len(rem):
        dd = max([len(v) for k, v in rem.items()])
    return N - dd


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    result = solve(N, x, y)
    print(result)

if __name__ == '__main__':
    main()

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]))
cxy = sorted(XY, 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
    if (p, q) == (0, 0) or (p, q) in diff:
      continue
    diff.append((p, q))

pre = []
ans = []
arr=XY[:]
for p, q in diff:
  if p < 0 and q < 0:
    arr = cxy[:]
  else:
    arr = XY[:]
  cost = 1
  for a, b in arr:
    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 numpy as np
N = int(input())
pair_list = []
diff_list = {}
duplex = 0
for _ in range(N):
  new_pair = list(map(int, input().split()))
  if new_pair in pair_list:
    duplex += 1
  else:
    for pair in  pair_list:
      diff = tuple(np.array(pair) - np.array(new_pair))
      if diff in diff_list:
        diff_list[diff] += 1
      else:
        diff_list[diff] = 1
    pair_list.append(new_pair)
if N == 1:
  print(N)
else:
  print(N - max(max(diff_list.values()), duplex))

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


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

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

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

        g = (len(l) - len(l & r))
        ans = max(ans, len(l | r) - g)
        print(v, len(l | r), g, l & r)
    return N - ans


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
balls = [
    [int(s) for s in input().split(' ')]
    for i in range(N)
]
balls.sort(key=lambda p: p[0])
d = {}
d_max = -1
for i in range(N):
    for j in range(i + 1, N):
        p = balls[j][0] - balls[i][0]
        q = balls[j][1] - balls[i][1]
        if not p in d:
            d[p] = {}
        d[p][q] = (d[p][q] if q in d[p] else 0) + 1
        d_max = max([d_max, d[p][q]])
print(N - d_max)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

if N == 1:
    print(1)
else:
    d = defaultdict(int)
    for i, pp1 in enumerate(p):
        for j in range(i + 1, N):
            pp2 = p[j]
            d[(pp1[0] - pp2[0], pp1[1] - pp2[1])] += 1

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

Submission status: Wrong Answer

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

if n <= 2:
    print(1)

else:
    L_sort = sorted(L, key=lambda x:(x[0]+x[1]))
    L_dict = {}
    for i in range(n-1):
        tmp0 = L_sort[i+1][0] - L_sort[i][0]
        tmp1 = L_sort[i+1][1] - L_sort[i][1]
        if (tmp0, tmp1) in L_dict:
            L_dict[(tmp0, tmp1)] += 1
        else:
            L_dict[(tmp0, tmp1)] = 1
    ans = n - max(L_dict.values())
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

print(len(set(y)))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
answer = []
answer2 = []
lis = []
lis2 = []
for i in range(N):
    x, y = map(int, input().split())
    lis.append([x, y])
    lis2.append([y, x])
sort_lis = sorted(lis)
sort_lis2 = sorted(lis2)

if N == 1:
    print(1)
    exit()
for i in range(N-1):
    answer.append([sort_lis[i][0] -sort_lis[i+1][0],sort_lis[i][1]-sort_lis[i+1][1]])
    answer2.append([sort_lis2[i][0] -sort_lis2[i+1][0],sort_lis2[i][1]-sort_lis2[i+1][1]])
ans = list(map(tuple,answer))
#print(ans)
ans2 = list(map(tuple,answer2))
#print(ans2)
a = Counter(ans).most_common()
#print(a)
a2 = Counter(ans2).most_common()
#print(a2)
if len(a)==1 or len(a2)==1:
    print(1)
    exit()
if a[0][1] >= a2[0][1]:
    c = 1
    for i in range(1,len(a)):
        c += a[i][1]

else:
    c = 1
    for i in range(1,len(a2)):
        c += a2[i][1]
print(c)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from itertools import combinations
from collections import defaultdict, Counter

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

slopes = defaultdict(list)

if N == 1:
    print(1)
else:
    for a, b in combinations(balls, 2):
        delta_x = a[0] - b[0]
        delta_y = a[1] - b[1]
        if delta_x * delta_y == 0:
            lis = [0, 0]
            if delta_y:
                lis[0] = 1
                intercept = a[0]
                slopes[tuple(lis)].append(intercept)
            else:
                lis[1] = 1
                intercept = a[1]
                slopes[tuple(lis)].append(intercept)
        else:
            key = Fraction(delta_y, delta_x)
            den = key.denominator
            num = key.numerator
            intercept = Fraction(den * a[1] - num * a[0], den)
            slopes[key].append(intercept)
    benefit_dict = {
        n * (n + 1) // 2: n for n in range(1, 51)
    }
    costs = []
    for k, v in slopes.items():
        c = Counter(v)
        lis = list(c.values())
        benefits = [benefit_dict[l] for l in lis]
        costs.append(N - sum(benefits))

    print(min(costs))

Submission status: Wrong Answer

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

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

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

ll=[]
for i in range(n):
    j=1
    while abs(xy[i][0])-j*p>=0:
        if p==0:
            break
        j+=1
    k=1
    while abs(xy[i][1])-k*q>=0:
        if q==0:
            break
        k+=1
    ll.append((abs(xy[i][0])-(j-1)*p,abs(xy[i][1])-(k-1)*q))
c=collections.Counter(ll)
pp=c.most_common()
print(len(pp))

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])*2 + (alllist[i+1][1]-alllist[i][1] + 1))



    countdict = collections.Counter(minaslist)

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

    print(len(minaslist) - mostnum + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

xy.sort()
yx.sort()
cost_x,cost_y = [],[]
for j in range(n-1):
    cost_x.append(xy[j+1][0]-xy[j][0])
    cost_y.append(yx[j+1][0]-yx[j][0])

cost_x = list(set(cost_x))
cost_y = list(set(cost_y))
cost = max(len(cost_x),len(cost_y))

print(cost)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    xy = [list(map(int, input().split())) for _ in range(n)]
    ans = float('inf')

    for first in range(n):
        for second in range(n):
            if first != second:
                p = xy[first][0] - xy[second][0]
                q = xy[first][1] - xy[second][1]

                for pi, qi in zip([p, -p], [q, -q]):
                    prev_a = xy[first][0]
                    prev_b = xy[first][1]
                    count = 0

                    for i in range(n):
                        if i != first:
                            if (xy[i][0] - pi) != prev_a or (xy[i][1] - qi) != prev_b:
                                count += 1

                            prev_a = xy[i][0]
                            prev_b = xy[i][1]

                    ans = min(ans, count)

    print(ans + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = list(list(map(int,input().split()))+[0]for i in range(N))
xy.sort()
ans = 50
hoge = 0
p,q = 0,0

def func(n):
    xy[n][2] = 1
    if [xy[n][0]+p,xy[n][1]+q,0] in xy:
        func(xy.index([xy[n][0]+p,xy[n][1]+q,0]))
    if [xy[n][0]-p,xy[n][1]-q,0] in xy:
        func(xy.index([xy[n][0]-p,xy[n][1]-q,0]))
    


for i in range(N):
    for j in range(i+1,N):
        p,q = xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]
        for k in range(N):
            if xy[k][2] == 0:
                func(k)
                hoge += 1
        ans = min(hoge,ans)
        hoge = 0
        for k in range(N):
            xy[k][2] = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations


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

for b1, b2 in combinations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    if p != 0 and q != 0:
        sub = 0
        for ball in balls:
            bx, by = ball
            dx, dy = bx - b2[0], by - b2[1]
            if dx % p == 0 and dy % q == 0 and dx // p == dy // q:
                sub += 1
        cost = min(cost, n - sub)

print(max(cost, 1))