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())
ary = []
d = []
d2 = []
for _ in range(N):
  ball = list(map(int, input().split()))
  ary.append(ball)

for i in range(N-1):
    x = ary[i][0] - ary[i+1][0]
    y = ary[i][1] - ary[i+1][1]
    # d.append(x)
    # d.append(y)
    tmp = str(x) + str(y)
    d2.append(tmp)
    d = []
# print(ary)
# print(d2)

print(len(set(d2)))

Submission status: Wrong Answer

Solution code:
n = int(input())
coords = []
dist = {}
for i in range(n):
    a, b = (int(_) for _ in input().split())
    for coord in coords:
        x = abs(coord[0] - a)
        y = abs(coord[1] - b)
        if (x,y) not in dist:
            dist[(x,y)] = 1
        else:
            dist[(x,y)] = dist[(x,y)] + 1
    coords.append([a,b])
if n == 1 or n == 2:
    print(1)
else:
    ans = 0
    for distance in dist:
        if dist[distance] > ans:
            ans = dist[distance]
    print(n - ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import numpy as np
from collections import Counter
ls_x = []
ls_y = []
diff = []
N = int(input())
for n in range(N):
    x,y = map(int,input().split())
    for i in range(len(ls_x)):
        diff.append(str(abs(ls_x[i] - x))+"_"+str(abs(ls_y[i] - y)))
    ls_x.append(x)
    ls_y.append(y)
if N == 1:
    print (1)
    exit()
cnt = Counter(diff)
#print (cnt.most_common())
print (N-cnt.most_common(1)[0][1])

Submission status: Wrong Answer

Solution code:
N = int(input())

l = []
for _ in range(N) :
    ll = list(map(int, input().split()))
    l.append(ll)

#print(l)

dic = {}

for i in range(1, N) :
    #subl.append([l[i][0] - l[i-1][0], l[i][1] - l[i-1][1]])
    #k = 1000000001*(l[i][0] - l[i-1][0]) + l[i][1] - l[i-1][1]
    k = str(l[i][0] - l[i-1][0]) + '+' + str(l[i][1] - l[i-1][1])

    if l[i][0] - l[i-1][0] == 0 and l[i][1] - l[i-1][1] == 0:
        continue

    if k not in dic :
        dic[k] = 1
    else :
        dic[k] += 1

print(dic)

if len(dic) == 0 :
    print(N)
else :
    print(N - max(dic.values()))

Submission status: Wrong Answer

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

Xi = sorted(Xi)
Yi = sorted(Yi)

dictX = {}
dictY = {}
for i in range(N - 1):
    x, y = Xi[i], Yi[i]
    nx, ny = Xi[i + 1], Yi[i + 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 = Xi[i], Yi[i]
    nx, ny = Xi[i + 1], Yi[i + 1]
    tx = x - nx
    ty = y - ny
    if tx == p and ty == q:
        pass
    else:
        cost += 1

print(cost)

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

Submission status: Wrong Answer

Solution code:
def most_frequent(List):
    counter = 0
    num = List[0]

    for i in List:
        curr_frequency = List.count(i)
        if(curr_frequency> counter):
            counter = curr_frequency
            num = i

    return num

n = int(input())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([x,y])
try:
    l = []
    for i in range(len(c)-1):
        for j in range(i+1,len(c)):
            l.append([c[j][0]-c[i][0],c[j][1]-c[i][1]])

    z = most_frequent(l)
    l = 1
    for i in range(1,len(c)):
        if([c[i][0]-z[0],c[i][1]-z[1]] not in c):
            l+=1
    print(l)
except:
    print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
ans = set()
for i in range(n-1):
  a, b = arr[i]
  c, d = arr[i+1]
  x, y = (a-c), (b-d)
  ans.add((x,y))
print(len(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
List=[list(map(int,input().split())) for i in range(N)]
A = []
b =[]
for i in range(N):
    for j in range(i):
        if List[i][0] > List[j][0]:
            a = [List[i][0]-List[j][0],List[i][1]-List[j][1]]
        elif List[i][0] < List[j][0]:
            a = [List[j][0]-List[i][0],List[j][1]-List[i][1]]
        else:
            if List[i][1] > List[j][1]:
                a = [List[i][0]-List[j][0],List[i][1]-List[j][1]]
            elif List[i][1] < List[j][1]:
                a = [List[j][0]-List[i][0],List[j][1]-List[i][1]]
        b.append(A.count(a))
        A.append(a)
if b == []:
    print(0)
else:
    print(N-max(b)-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_ = [tuple(map(int, input().split())) for i in range(n)]
list_1 = sorted(list_)
list_2 = sorted(list_, key=lambda x: x[1])

res = []
for list_n in (list_1, list_2):
    ab = []
    x_1, y_1 = list_n[0]
    for x_2, y_2 in list_n[1:]:
        a = x_2 - x_1
        b = y_2 - y_1
        ab.append((a, b))
        x_1, y_1 = x_2, y_2
    res.append(len(set(ab)))

print(min(res))

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 list(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):
    XY = [tuple(v) for v in XY]
    XY.sort()

    @lru_cache(maxsize=None)
    def f(i, v, x, y):
        ans = 0
        for j, u in enumerate(XY[i+1:]):
            if v[0] - u[0] == x and v[1] - u[1] == y:
                ans = max(ans, f(i+j+1, u, x, y) + 1)
            else:
                ans = max(ans, f(i+j+1, u, x, y))
        return ans

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if XY[i][0]-XY[j][0] == 0 and XY[i][1]-XY[j][1] == 0:
                continue
            ans = max(ans, f(i, XY[i], XY[i][0]-XY[j][0], XY[i][1]-XY[j][1]))
    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())
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]))


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())
coords = []
dist = {}
for i in range(n):
    a, b = (int(_) for _ in input().split())
    for coord in coords:
        x = abs(coord[0] - a)
        y = abs(coord[1] - b)
        if (x,y) not in dist:
            dist[(x,y)] = 1
        else:
            dist[(x,y)] = dist[(x,y)] + 1
    coords.append([a,b])
if n == 1 or n == 2:
    print(1)
else:
    ans = 0
    for distance in dist:
        if dist[distance] > ans:
            ans = dist[distance]
            print(distance)
    print(n - ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    xy = ii2nnn(N)
    dicx = defaultdict(lambda: 0)
    xy.sort(key=lambda v: v[0])
    for i in range(1, len(xy)):
        dx = xy[i][0] - xy[i-1][0]
        dy = xy[i][1] - xy[i-1][1]
        if dx == 0 and dy == 0:
            continue
        key = '%d %d' % (dx, dy)
        dicx[key] += 1
    dicy = defaultdict(lambda: 0)
    xy.sort(key=lambda v: v[1])
    for i in range(1, len(xy)):
        dx = xy[i][0] - xy[i-1][0]
        dy = xy[i][1] - xy[i-1][1]
        if dx == 0 and dy == 0:
            continue
        key = '%d %d' % (dx, dy)
        dicy[key] += 1
    nm = 0
    for v in dicx.values():
        if nm < v:
            nm = v
    for v in dicy.values():
        if nm < v:
            nm = v
    print(N - nm)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
ball = [tuple(map(int, input().split())) for _ in range(N)]
ball.sort(key=lambda x:(x[0], x[1]))
diff = [tuple((ball[i][0] - ball[i-1][0], ball[i][1] - ball[i-1][1])) for i in range(1,N)]
unique = set(diff)
if len(unique) == 1:
  print(1)
else:
  print(N - len(unique))

Submission status: Wrong Answer

Solution code:
from copy import *
from collections import*
n=int(input())
if n==1:
    print(0)
    exit()
p=[list(map(int,input().split()))for i in range(n)]
l=[]
for i in range(n):
    q=deepcopy(p)
    a,b=q.pop(i)
#    print(a,q)
    l.extend([(s-a,t-b)for s,t in q])
print(n-(Counter(l).most_common()[0][1]+1)+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
for i in range(N):
  x, y = [int(item) for item in input().split()]
  X.append(x)
  Y.append(y)
result={}
maxv = -100
for i in range(N):
    for j in range(N):
      dx, dy = X[j]-X[i], Y[j]-Y[i]
      if dx > 0 or dy > 0:
        if (dx, dy) not in result:
          result[(dx, dy)] = 1
        else:
          result[(dx, dy)] += 1
        if result[(dx, dy)]>maxv:
          maxv=result[(dx, dy)]
print (N-maxv)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
x=[]
y=[]

for i in range(n):
    aa=list(input().split())
    x.append(int(aa[0]))
    y.append(int(aa[1]))
z=[]
if n==1 or n==2:
    print(1)
else:
    for i in range(n-1):
        z.append((x[i]-x[i+1],y[i]-y[i+1]))

    c = collections.Counter(z)
    print(n-c.most_common()[0][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):
        if xy[i][0]-xy[j][0] == 0 or  xy[i][1]-xy[j][1] == 0:
            continue
        if (xy[i][0]-xy[j][0], xy[i][1]-xy[j][1]) in d:
            d[(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])] += 1
        else:
            d[(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])] = 1

for val in d.values():

    m = max(m, val)
#print(d)
print(N-m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import product
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

xy.sort(key=lambda x: (x[0], x[1]))
m = 0
for i, j in product(range(n - 1), range(n)):
    if i >= j:
        continue
    p = xy[j][0] - xy[i][0]
    c = 0
    for k in range(n - 1):
        for l in range(k + 1, n):
            if xy[l][0] - xy[k][0] == p:
                c += 1
                break
    m = max(m, c)

xy.sort(key=lambda x: (x[1], x[0]))
for i, j in product(range(n - 1), range(n)):
    if i >= j:
        continue
    q = xy[j][1] - xy[i][1]
    c = 0
    for k in range(n - 1):
        for l in range(k + 1, n):
            if xy[l][1] - xy[k][1] == q:
                c += 1
                break
    m = max(m, c)

print(n - m)

Submission status: Wrong Answer

Solution code:
import itertools


n = int(input())
xs, ys = list(), list()
points = list()
for i in range(n):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)
    points.append((x, y))

candidates = list()
indices = itertools.combinations(range(n), 2)
points = sorted(points)
for i, j in indices:
    p = points[j][0] - points[i][0]
    q = points[j][1] - points[i][1]
    candidates.append((p, q))

ans = n * 2
for p, q in candidates:
    indices = list(range(n))
    cost = 0

    idx = 0
    cost += 1

    while True:
        x, y = points[idx]
        indices.remove(idx)
        if len(indices) == 0:
            break

        try:
            idx = points.index((x + p, y + q))
        except Exception:
            idx = indices[0]
            cost += 1
    
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
x = np.zeros(N)
y = np.zeros(N)
for i in range(N):
    x[i], y[i] = map(int, input().split())
for j in range(N-1):
    for k in range(N-1):
        if x[k] > x[k + 1]:
            x[k], y[k] = x[k + 1], y[k + 1]

ans = N
for m in range(N):
    for p in range(m):
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = N
        for q in range(N):
            for r in range(q):
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari -= 1
        if ans_kari < ans:
            ans = ans_kari
print("{}".format(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 list(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):
    XY = [tuple(v) for v in XY]
    XY.sort()

    @lru_cache(maxsize=None)
    def f(i, v, x, y):
        ans = 0
        for j, u in enumerate(XY[i+1:]):
            if v[0] - u[0] == x and v[1] - u[1] == y:
                ans = max(ans, f(i+j+1, u, x, y) + 1)
            else:
                ans = max(ans, f(i+j+1, u, x, y))
        return ans

    ans = 0
    for i in range(N):
        print(i)
        for j in range(i+1, N):
            if XY[i][0]-XY[j][0] == 0 and XY[i][1]-XY[j][1] == 0:
                continue
            ans = max(ans, f(i, XY[i], XY[i][0]-XY[j][0], XY[i][1]-XY[j][1]))
    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())
A = [[int(s) for s in input().split()] for _ in range(N)]
cost = N
for x0, y0 in A:
    for x1, y1 in A:
        if not (x0 == x1 and y0 == y1):
            p = x0 - x1
            q = y0 - y1
            cost = min([cost, len(set([q * a[0] - p * a[1] for a in A]))])
print(cost)

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

y = x[:]
z = x[:]
sorted(y, key=lambda x: x[0])
sorted(z, key=lambda x: x[1])

a = y[0][0]
b = y[0][1]
ls1 = []
for i in y:
    p = i[0]
    q = i[1]
    ls1.append([a - p, b - q])
    a = p
    b = q
c = []
for i in ls1:
    c.append(ls1.count(i))
ans = N - max(c)

a = z[0][0]
b = z[0][1]
ls1 = []
for i in z:
    p = i[0]
    q = i[1]
    ls1.append([a - p, b - q])
    a = p
    b = q
c = []
for i in ls1:
    c.append(ls1.count(i))
ans = min(ans,N - max(c))
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)

    pqmap = defaultdict(list)

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

            p = abs(x1 - x2)
            q = abs(y1 - y2)
            g = gcm(p, q)
            p = p // g
            q = q // g

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

    pqcount = defaultdict(int)
    for (p, q), ijlist in pqmap.items():
        checkedlist = []
        for i, j in ijlist:
            if i in checkedlist and j in checkedlist:
                continue
            checkedlist.append(i)
            checkedlist.append(j)
            pqcount[(p, q)] += 1

    maxpqcount = 0
    for count in pqcount.values():
        maxpqcount = max(maxpqcount, count)

    print(n - maxpqcount)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]


    ans = num
    for i in range(num):
        for j in range(num):
            if i == j:
                continue

            now_kyori = [data[i][0] - data[j][0], data[i][1] - data[j][1]]
            visit_list = [0 for i in range(num)]
            visit_list[i], visit_list[j] = 1, 1

            kari_num = 1

            for k in range(num):
                if visit_list[k]:
                    continue

                now_data = data[k]

                flg = 1
                for l in range(num):
                    if visit_list[l]:
                        a = data[l][0] - now_data[0]
                        b = data[l][1] - now_data[1]

                        if now_kyori[0] == 0 and now_kyori[1] == 0:
                            if a == now_kyori[0] and b == now_kyori[0]:
                                flg = 0
                        elif now_kyori[0] == 0:
                            if a == now_kyori[0] and b % now_kyori[1] == 0:
                                flg = 0
                        elif now_kyori[1] == 0:
                            if b == now_kyori[1] and a % now_kyori[0] == 0:
                                flg = 0
                        else:
                            if a % now_kyori[0] == 0 and b % now_kyori[1] == 0:
                                if a // now_kyori[0] == b // now_kyori[1]:
                                    flg = 0
                        if flg == 0:
                            break

                if flg:
                    kari_num += 1
                visit_list[k] = 1


            ans = min(kari_num, ans)

    print(ans)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Xi = sorted(Xi)
Yi = sorted(Yi)

dictX = {}
dictY = {}
for i in range(N - 1):
    x, y = Xi[i], Yi[i]
    nx, ny = Xi[i + 1], Yi[i + 1]
    tx = abs(x - nx)
    ty = abs(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 = Xi[i], Yi[i]
    nx, ny = Xi[i + 1], Yi[i + 1]
    tx = abs(x - nx)
    ty = abs(y - ny)

    if tx == p and ty == q:
        pass
    else:
        cost += 1

print(cost)

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()
d = defaultdict(int)
m = 0
for i in range(n-1):
    x1, y1 = xy[i]
    x2, y2 = xy[i+1]
    z1 = x2-x1
    z2 = y2-y1
    if z1 != 0 or z2 != 0:
        d["%d:%d" % (x2-x1, y2-y1)] += 1
        if m < d["%d:%d" % (x2-x1, y2-y1)]:
            m = d["%d:%d" % (x2-x1, y2-y1)]

print(n-m)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [list(map(int, input().split()))]
t = []

for i in range(n - 1):
  l.append(list(map(int, input().split())))
  n1 = l[i][0] - l[i+1][0]
  n2 = l[i][1] - l[i+1][1]
  t.append([n1, n2])

s = list(map(list, set(map(tuple, t))))

a = 0
for i in range(len(s)):
  w = t.count(s[i])
  a = max(a, w)

ans = n - a

print(ans)

Submission status: Wrong Answer

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

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

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

PQ = {}

for i in range(N):
    x0, y0 = XY[i]
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[j]
        p, q = x0 - x1, y0 - y1
        key = str(p) + ',' + str(q)
        if key in PQ:
            PQ[key] += 1
        else:
            PQ[key] = 1
ansL = PQ.values()
print(N - max(list(ansL)))

Submission status: Wrong Answer

Solution code:
def most_frequent(List):
    counter = 0
    num = List[0]

    for i in List:
        curr_frequency = List.count(i)
        if(curr_frequency> counter):
            counter = curr_frequency
            num = i

    return num

n = int(input())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([x,y])
if(n==1):
    print(1)
    exit()
l = []
for i in range(len(c)-1):
    for j in range(i+1,len(c)):
        l.append([c[j][0]-c[i][0],c[j][1]-c[i][1]])

z = most_frequent(l)
l = 1
for i in range(1,len(c)):
    if([c[i][0]-z[0],c[i][1]-z[1]] not in c):
        l+=1
print(l)

Submission status: Wrong Answer

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

diff = []
for i in range(1,N):
    diff_x = d[i][0] - d[i-1][0]
    diff_y = d[i][1] - d[i-1][1]
    diff += [[diff_x, diff_y]]

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

print(len(diff_u))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

lst = []

for i in range(n):
    for j in range(i,n):
        if a[j][0]-a[i][0] <= 0 and a[j][1]-a[i][1] <= 0:
            lst.append([a[i][0]-a[j][0], a[i][1]-a[j][1]])
        else:
            lst.append([a[j][0]-a[i][0], a[j][1]-a[i][1]])

if n ==1:
    print(1)
else:
    x = 0
    for i in range(len(a)):
        c = 0
        for j in range(i,len(a)):
            if a[i] == a[j]:
                c += 1
        x = max(x,c)
    print(n-x-1)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

pqlist = []
for i in range(len(balls)):
    for j in range(i+1, len(balls)):
        pqlist.append((balls[j][0] - balls[i][0], balls[j][1] - balls[i][1]))

saishouti = 10**9 + 7

ballset = set(balls)
for pq in pqlist:
    count = 0
    for ball in ballset:
        if (ball[0] + pq[0], ball[1] + pq[1]) in ballset:
            count += 1

    saishouti = min(saishouti, len(balls)-count)

print(saishouti)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def count_cost(xy: list, a: int):
    n = len(xy)
    done = [False]*n

    cnt = 0

    for i, (xi, yi) in enumerate(xy):
        if done[i]:
            continue

        done[i] = True
        for j, (xj, yj) in enumerate(xy):
            if j <= i:
                continue

            if xi == xj:
                continue

            elif (yi - yj) / (xi - xj) == a:
                done[j] = True

        cnt += 1


    return cnt


n = ni()
xy = [list(li()) for _ in range(n)]

ans = n
for i in range(n):
    for j in range(i+1, n):
        xi, yi = xy[i]
        xj, yj = xy[j]

        if xi == xj:
            continue

        a = (yi - yj) / (xi - xj)

        ans = min(ans, count_cost(xy, a))

print(ans)

Submission status: Wrong Answer

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

cost_min = 10 ** 4
cost = 1
if N == 1 or N == 2:
  print(1)
else:
  xy.sort()
  for i in range(N-1):
    p = xy[i][0] - xy[i+1][0]
    q = xy[i][1] - xy[i+1][1]
    for j in range(N-1):
      if xy[j+1][0] + p == xy[j][0] and xy[j+1][1] + q == xy[j][1]:
        pass
      else:
        cost += 1
    if cost < cost_min:
      cost_min = cost
      
  print(cost_min)

Submission status: Wrong Answer

Solution code:
from itertools import permutations


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

min_cost = n
for xyi, xyj in permutations(xys, 2):
    xi, yi = xyi
    xj, yj = xyj
    p = xj - xi
    q = yj - yi

    line_list = []
    cost = n
    for x, y in xys:
        line_list.append((x, y))
        for xx, yy in line_list:
            if x == xx - p and y == yy - q:
                cost -= 1
                continue
    min_cost = min(min_cost, cost)

print(min_cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
answer = []
lis = []

for i in range(N):
    x, y = map(int, input().split())
    lis.append([x, y])
sort_lis = sorted(lis)
#print(sort_lis)
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]])
ans = list(map(tuple,answer))
ans = set(ans)
print(len(ans))