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: Runtime Error

Solution code:
import itertools
import collections

N = int(input())

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

combinations = list(itertools.combinations(dict_xy, 2))
# combinations = list(itertools.permutations(dict_xy, 2))
relative_coordinates = []

for combination in combinations:
    key1 = combination[0]
    key2 = combination[1]

    x1 = dict_xy[key1][0]
    y1 = dict_xy[key1][1]
    x2 = dict_xy[key2][0]
    y2 = dict_xy[key2][1]

    if x1 + y1 > x2 + y2:
        x1, y1, x2, y2 = x2, y2, x1, y1
    elif x1 + y1 == x2 + y2 and x1 > x2:
        x1, y1, x2, y2 = x2, y2, x1, y1

    relative_coordinates.append((x1 - x2, y1 - y2))

counter = 1 # collections.Counter(relative_coordinates)
cost = N - counter.most_common()[0][1]
print(cost)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
ball = [[int(i) for i in input().split()] for k in range(N)]
diff = []
for i in range(N):
    for j in range(i+1, N):
        diff.append((abs(ball[i][n]-ball[j][n]) for n in range(2)))
k = Counter(diff).most_common()[0][1]
print(max(1,N-1-k))

Submission status: Runtime Error

Solution code:
import collections

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

for i in range(N):
  for j in range(N):
    pq.append((xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]))
c = collections.Counter(pq)
if c.most_common()[0][0] == (0,0):
  ans -= c.most_common()[1][1]
else:
  ans -= c.most_common()[0][1]
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
xy_list = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
while (xy_list):
    cnt += 1
    x0, y0 = xy_list.pop(0)
    if (len(xy_list) == 0): break
    max_cnt = 0
    first = True
    for i, (x, y) in enumerate(xy_list):
        dx = x0 - x
        dy = y0 - y
        c = x0*dy - y0*dx
        if (dx * dy == 0): continue
        else:
            if (first): index = i; first = False
            tmp = 0
            for xi, yi in xy_list:
                if ((x, y) == (xi, yi)): continue
                if (dy*xi - dx*yi == c):
                    tmp += 1
            if (tmp > max_cnt):
                index = i
                max_cnt = tmp
    x1, y1 = xy_list.pop(index)
    dx = x0 - x
    dy = y0 - y
    c = x0*dy - y0*dx
    xy_list = list(filter(lambda xy: dy*xy[0] - dx*xy[1] != c, xy_list))
print(cnt)

Submission status: Runtime Error

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

balls=[]
for i in range(N):
  balls.append( [int(i) for i in input().split()])

salist=[]
sa_uniq=[]
for i in range(1,len(balls),1):
  sax = balls[i][0]-balls[i-1][0]
  say = balls[i][1]-balls[i-1][1]
  salist.append([sax,say])
  if [sax,say] not in sa_uniq:
    sa_uniq.append([sax,say])

count = []
for sa in sa_uniq:
  count.append(salist.count(sa))

if N-max(count)==1:
  print('1')
else:
  print(N-max(count))

Submission status: Runtime Error

Solution code:
N = int(input())

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

d = []
e = []

for i in range(N-1):
    for j in range(i+1,N):
        p = (x[i]-x[j])
        q = (y[i]-y[j])

        a = [p,q]
        d.append(a)

max = 0

for i in range(N):
    if max < d.count(d[i]):
        max = d.count(d[i])

if max == N:
    max = N-1

print(N-max)

Submission status: Runtime Error

Solution code:

def check_other(tmp_i, cur_p, cur_q, cur_x, cur_y, tmp_count):
    for i in range(len(p)):
        if i in tmp_i:
            continue

        tmp_p = p[i][0] - cur_x
        tmp_q = p[i][1] - cur_y

        if tmp_p == cur_p and tmp_q == cur_q:
            tmp_i.append(i)

            tmp_count += 1
            tmp_count = check_other(tmp_i, cur_p, cur_q, p[i][0], p[i][1], tmp_count)


    return tmp_count





if __name__ == "__main__":
    #入力取得
    N = int(input())

    p = []


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

    min_cost = N

    results = []

    counts = []

    for j in range(len(p)):
        for i in range(len(p)):
            tmp_i = [i]
            tmp_count = 0
            if i == 0:
                continue

            tmp_p = p[i][0] - p[j][0]
            tmp_q = p[i][1] - p[j][1]



            tmp_count = check_other(tmp_i, tmp_p, tmp_q, p[i][0], p[i][1], tmp_count)


            counts.append(tmp_count)




tmp_max = max(counts)

if N == 2:
    result = 1
elif tmp_max == 0:
    result = N - 2
else:
    result = N - tmp_max - 1
#
print(result)

Submission status: Runtime Error

Solution code:
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
dic = {}
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    size = fractions.gcd(vec[0],vec[1])
    vec[0] = vec[0]//size
    vec[1] = vec[1]//size
    if vec[0]<0 and vec[1]<0:
      vec[0] = -vec[0]
      vec[1] = -vec[1]
    vec = tuple(vec)
    if vec not in dic.keys():
      dic[vec] = set([j])
    else:
      dic[vec].add(j)
m = 0
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
q_list = []
a_list = []
for i in range(n):
    q = []
    x, y = map(int, input().split())
    q.append(x)
    q.append(y)
    q_list.append(q)
    if i != 0:
        for j in range(i):
            difx1 = q_list[j][0] - q_list[i][0]
            dify1 = q_list[j][1] - q_list[i][1]
            difx2 = q_list[i][0] - q_list[j][0]
            dify2 = q_list[i][1] - q_list[j][1]
            a_list.append(f"{difx1}{dify1}")
            a_list.append(f"{difx2}{dify2}")
if n != 1:
    c = collections.Counter(a_list)
    zero = c.most_common()[0][1]
    print(n-zero)
else:
    print(1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
if N == 1:
    print(1)
else:
    P = [[0,0] for _ in range(N*(N-1)//2)]
    num = 0
    are = 0
    for i in range(N):
        for j in range(i+1, N):
            P[num][0] = A[i][0] - A[j][0]
            P[num][1] = A[i][1] - A[j][1]
            num += 1
    for i in range(len(P)):
        cnt= 1
        for j in range(i+1, len(P)):
            if P[i][0] == 0 or P[i][1] == 0 or P[j][0] == 0 or P[j][1] == 0:
                if (P[i][0] == 0 and P[j][0] == 0) or P[i][1] ==0 and P[j][1] == 0:
                    cnt += 1
            else:
                if (P[i][0] % P[j][0] == 0 and P[i][1] % P[j][1] == 0) or (P[j][0] % P[i][0] == 0 and P[j][1] % P[i][1] ==0):
                    cnt += 1
        are = max(cnt, are)
print(max((N - are), 1))

Submission status: Runtime Error

Solution code:
import collections
 
N=int(input())
x=[0]*N
y=[0]*N
a=[]
b=[]
c=1
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])

X=collections.Counter(a).most_common()[0][1]
Y=collections.Counter(b).most_common()[0][1]

print(N-max(X,Y))

Submission status: Runtime Error

Solution code:
N=int(input())
xy_list = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
while (xy_list):
    cnt += 1
    x0, y0 = xy_list.pop(0)
    if (len(xy_list) == 0): break
    max_cnt = 0
    for i, (x, y) in enumerate(xy_list):
        dx = x0 - x
        dy = y0 - y
        c = x0*dy - y0*dx
        if (dx * dy == 0): continue
        else:
            if (max_cnt == 0): index = i
            tmp = 0
            for xi, yi in xy_list:
                if ((x, y) == (xi, yi)): continue
                if (dy*xi - dx*yi == c):
                    tmp += 1
            if (tmp > max_cnt):
                index = i
                max_cnt = tmp
    x1, y1 = xy_list.pop(index)
    dx = x0 - x
    dy = y0 - y
    c = x0*dy - y0*dx
    xy_list = list(filter(lambda xy: dy*xy[0] - dx*xy[1] != c, xy_list))
print(cnt)

Submission status: Runtime Error

Solution code:

from collections import Counter

# data = [[1, 1], [1, 2], [2, 1], [2, 2]]
# N = len(data)

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

for i in range(N):
    data.extend([list(map(int, input().split(" ")))])
x = []

for e_set in data:
    for sub_set in data:
        x.append((e_set[0] - sub_set[0], e_set[1] - sub_set[1]))
a = (0, 0)

while a in x:
    x.remove(a)
val = Counter(x)

common_times = val.most_common()[0][1]
ans = N - common_times

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N=int(input())
listX=[]
listY=[]
listP=[]
listQ=[]
for i in range(N):
  x,y=map(int,input().split())
  listX+=[x]
  listY+=[y]
for i in range(N):
  for k in range(N):
    if i>k:
      listP+=[(listY[i]-listY[k])/(listX[i]-listX[k])]
counter=Counter(listP)
for word, cnt in counter.most_common():
  listQ+=[cnt]
A=max(listQ)
print(N-A+1)

Submission status: Runtime Error

Solution code:
#標準入力
N = int(input())
S = []
S = [list(map(int, input().split())) for i in range(N)]

ans = 1
i = 0
j = 0
for _ in range(N):
  if i==N:
    break
  try:
    a =(S[i+1][1]-S[i][1])/(S[i+1][0]-S[i][0])
    b = S[i][1]-a*S[i][0]
    for _ in range(N):
      if j == N:
        i = N
        break
      if S[j][1]!=a*S[j][0]+b:
        ans+=1
        break
      else:
        S.remove(S[j])
        N -= 1
      j +=1  
  except:

    for _ in range(N):
      if j == N:
        i = N
        break
      if S[j][0]!=S[i][0]:
        ans+=1
        break
      else: 
        S.remove(S[j])
        N -= 1
      j+=1
    
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutations

n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
xy = sorted(xy, key=lambda xy: xy[0])

costs = []
for per in permutations(xy, n):
    cost = 1
    p = per[1][0] - per[0][0]
    q = per[1][1] - per[0][1]
    for i in range(2, n):
        if not (per[i][0] - per[i-1][0] == p and per[i][1] - per[i-1][1] == q):
            cost += 1
    costs.append(cost)
print(min(costs))

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

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

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

n = ni()
li = []
li2 = []
for i in range(n):
    x, y = na()
    li.append([x,y])
    li2.append((i,x*x+y*y))
li2.sort(key=lambda x:(x[1],x[0]))
#print(li2)
ct = 1
dif = []
li3 = []
for i in range(n-1):
    bbb = li2[i][0]
    ccc = li2[i][1]
    mae = li[li2[i][0]]
    li3.append(mae)
    tugi = li[li2[i+1][0]]
    if bbb == ccc and i > 0:
        dif.append([tugi[0] - li[li2[i-1][0]][0], tugi[1] - li[li2[i-1][0]][1]])
    dx = tugi[0] - mae[0]
    dy = tugi[1] - mae[1]

    #print(dx,dy)
    dif.append([dx, dy])
li3.append(li[li2[n-1][0]])
ddd = get_unique_list(dif)
#print(li3)
#print(ddd)
cl = []
for d in ddd:
    ct = 1
    for i in range(n-1):
        if [d[0]+li3[i][0], d[1]+li3[i][1]] not in li3:
            ct += 1
    cl.append(ct)
print(min(cl))

Submission status: Runtime Error

Solution code:
# 2019/06/15
# diverta 2019 Programming Contest 2 - B

from operator import itemgetter

# Input
n = int(input())
xylist = list()

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

xydist = list()

for i in range(n-1):
    for j in range(i+1, n):
        wx = abs(xylist[i][0] - xylist[j][0])
        wy = abs(xylist[i][1] - xylist[j][1])
        xydist.append([wx, wy])

xydist.sort()
maxcnt = 0
xmax = -1
ymax = -1
cnt = 1
for l in range(1, len(xydist)):
    if xydist[l] != xydist[l-1]:
        if maxcnt < cnt:
            maxcnt = cnt
            p = xydist[l-1][0]
            q = xydist[l-1][1]
        cnt = 1
    else:
        cnt += 1

if maxcnt < cnt:
    maxcnt = cnt
    p = xydist[len(xydist)-1][0]
    q = xydist[len(xydist)-1][1]

xylist.sort()

ans = 0
for i in range(len(xylist)):
    wx = xylist[i][0] + p
    wy = xylist[i][1] + q

    for j in range(i+1, len(xylist)):
        if xylist[j][0] == wx and xylist[j][1] == wy:
            ans -= 1
            break

    ans += 1

# Output
print(ans)

Submission status: Runtime Error

Solution code:

def check_other(tmp_i, cur_p, cur_q, cur_x, cur_y, tmp_count):
    for i in range(len(p)):
        if i in tmp_i:
            continue

        tmp_p = p[i][0] - cur_x
        tmp_q = p[i][1] - cur_y

        if tmp_p == cur_p and tmp_q == cur_q:
            tmp_i.append(i)

            tmp_count += 1
            tmp_count = check_other(tmp_i, cur_p, cur_q, p[i][0], p[i][1], tmp_count)


    return tmp_count





if __name__ == "__main__":
    #入力取得
    N = int(input())

    p = []


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

    min_cost = N

    results = []

    counts = []


    for i in range(len(p)):
        tmp_i = [i]
        tmp_count = 0
        if i == 0:
            continue

        tmp_p = p[i][0] - p[0][0]
        tmp_q = p[i][1] - p[0][1]



        tmp_count = check_other(tmp_i, tmp_p, tmp_q, p[i][0], p[i][1], tmp_count)


        counts.append(tmp_count)




tmp_max = max(counts)

if N == 2:
    result = 1
elif tmp_max == 0:
    result = N - 2
else:
    result = N - tmp_max - 1
#
print(result)

Submission status: Runtime Error

Solution code:

import itertools


def linerFunc(targetX, targetY, Xa, Ya, Xb, Yb):
    # print(f'{targetX} {targetY} {Xa} {Ya} {Xb} {Yb}')
    if Xb-Xa ==0:
        return False
    alpha = (Yb - Ya)/(Xb - Xa)
    beta = Yb - alpha * Xb
    val = float(alpha*targetX+beta)
    return True if val == targetY else False

def is_on(f,x,y):
    if f(x)==y:
        return True
    else:
        return False

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

funcs=[]
combs = list(itertools.combinations(points,2))


res=[]
for c in combs:
    count=0
    for p in points:
        if linerFunc(p[0],p[1],c[0][0],c[0][1],c[1][0],c[1][1]):
            count+=1
    res.append(count)
# print(N-max(res))
print(max(N-max(res),1))

Submission status: Runtime Error

Solution code:
N = int(input())

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

d = []

for i in range(N-1):
    for j in range(i+1,N):
        p = (x[i]-x[j])
        q = (y[i]-y[j])
        d.append([p,q])


num = []

for i in range(len(d)):
    for j in range(i+1):

        if i != j and(d[i]==d[j] or d[i]==d[j]*(-1)):
            num[j] += 1
            break

        if j == i:
            num.append(1)
            break



if num == []:
    X = 1
else:
    X = max(num)


if X == N:
    X = N-1

print(N-X)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N = int(input())
pair = []
for i in range(N):
    x, y = map(int, input().split())
    pair.append((x, y))
x = sorted(pair, key=lambda x: x[0])
y = sorted(pair, key=lambda x: x[1])
# sax = []
# say = []
sax = defaultdict(int)
say = defaultdict(int)
for i in range(len(x) - 1):
    sax[(x[i][0] - x[i + 1][0], x[i][1] - x[i + 1][1])] += 1
    say[(y[i][0] - y[i + 1][0], y[i][1] - y[i + 1][1])] += 1
x_cost = len(x) - max(sax.values())
y_cost = len(x) - max(say.values())
print(min(x_cost, y_cost))

Submission status: Runtime Error

Solution code:
from collections import Counter

# data = [[1, 1], [1, 2], [2, 1], [2, 2]]
# N = len(data)

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

for i in range(N):
    data.extend([list(map(int, input().split(" ")))])
x = []

for e_set in data:
    for sub_set in data:
        x.append((e_set[0] - sub_set[0], e_set[1] - sub_set[1]))
a = (0, 0)

while a in x:
    x.remove(a)
val = Counter(x)

common_times = val.most_common()[0][1]

if common_times == 1:
    common_times - 1
print(common_times)
ans = N - common_times

print(ans)

Submission status: Runtime Error

Solution code:

N = int(input())
t = [0] * N
x = [0] * N
for i in range(N):
    t[i], x[i] = map(int, input().split())
p, q = t[0]-t[1], x[0]-x[1]
cost1 = 1
cost2 = 1
for i in range(N-1):
    if t[i+1] !=  (t[i]-p) and x[i+1] != (x[i]-q):
        cost1 += 1
for i in reversed(range(N)):
    if t[i-1] !=  (t[i]-(-p)) and x[i-1] != (x[i]-(-q)) and i != 0:
        cost2 += 1

print(min(cost1, cost2))

Submission status: Runtime Error

Solution code:
N=int(input())
xy_list = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
while (xy_list):
    cnt += 1
    x0, y0 = xy_list.pop(0)

    max_cnt = 0
    for i, (x, y) in enumerate(xy_list):
        dx = x0 - x
        dy = y0 - y
        c = x0*dy - y0*dx
        if (dx * dy == 0): continue
        else:
            if (max_cnt == 0): index = i
            tmp = 0
            for xi, yi in xy_list:
                if ((x, y) == (xi, yi)): continue
                if (dy*xi - dx*yi == c):
                    tmp += 1
            if (tmp > max_cnt):
                index = i
                max_cnt = tmp
    x1, y1 = xy_list.pop(index)
    dx = x0 - x
    dy = y0 - y
    c = x0*dy - y0*dx
    xy_list = list(filter(lambda xy: dy*xy[0] - dx*xy[1] != c, xy_list))
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())

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

d = []

for i in range(N-1):
    for j in range(i+1,N):
        p = (x[i]-x[j])
        q = (y[i]-y[j])
        d.append([p,q])


print(d)
num = []

for i in range(len(d)):
    for j in range(i+1):

        if i != j and(d[i]==d[j] or d[i]==d[j]*(-1)):
            num[j] += 1
            break

        if j == i:
            num.append(1)
            break



if num == []:
    X = 1
else:
    X = max(num)


if X == N:
    X = N-1

print(N-X)

Submission status: Runtime Error

Solution code:
import itertools
import collections

N = int(input())

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

# combinations = list(itertools.combinations(dict_xy, 2))
combinations = list(itertools.permutations(dict_xy, 2))
relative_coordinates = []

for combination in combinations:
    key1 = combination[0]
    key2 = combination[1]

    xy1 = dict_xy[key1]
    xy2 = dict_xy[key2]

    relative_coordinates.append((xy2[0] - xy1[0], xy2[1] - xy1[1]))

counter = collections.Counter(relative_coordinates)
cost = N - counter.most_common()[0][1]
print(cost)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
x = []
for i in range(N):
	x.append(list(map(int, input().split())))
if N == 1
	print(1)
else:
	L = []
	for i in range(N):
		a, b = x[i][0], x[i][1]
		for j in range(N):
			if a > x[j][0] or b > x[j][1]:
				L.append((a - x[j][0], b - x[j][1]))
	c = collections.Counter(L)
	max = c.most_common(1)[0][1]
	print(N - max)

Submission status: Runtime Error

Solution code:
#標準入力
N = int(input())
S = []
S = [list(map(int, input().split())) for i in range(N)]

ans = 1
i = 0
j = 0
for _ in range(N):
  if i==N:
    break
  try:
    a =(S[i+1][1]-S[i][1])/(S[i+1][0]-S[i][0])
    b = S[i][1]-a*S[i][0]
    for _ in range(N):
      if j == N:
        i = N
        break
      if S[j][1]!=a*S[j][0]+b:
        ans+=1
        break
      else:
        S.remove(S[j])
        N -= 1
      j +=1  
  except:

    for _ in range(N):
      if j == N:
        i = N
        break
      if S[j][0]!=S[i][0]:
        ans+=1
        i = j
        break
      else: 
        S.remove(S[j])
        N -= 1
      j+=1
    
print(ans)

Submission status: Runtime Error

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

ans = n - max(patterns.values())

print(ans)

Submission status: Runtime Error

Solution code:
import collections
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


n=int(input())

arr=[]
for i in range(n):
    a,b=(map(int, input().split()))
    arr.append([a,b])
arr=sorted(arr, key=lambda x: x[1], reverse=True)
arr=sorted(arr, key=lambda x: x[0])

tmparr=[]
for num in range(len(arr)-1):
    #print(num)
    #tmparr=[]
    #for nn,i in enumerate(arr):
    for nn,i in enumerate(arr[num+1:]):
        #if nn==num:
        #    continue
        g=gcd(arr[num][0]-i[0],arr[num][1]-i[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: Runtime Error

Solution code:
import itertools
import collections

N = int(input())

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

# combinations = list(itertools.combinations(dict_xy, 2))
combinations = list(itertools.permutations(dict_xy, 2))
relative_coordinates = []

for combination in combinations:
    key1 = combination[0]
    key2 = combination[1]

    xy1 = dict_xy[key1]
    xy2 = dict_xy[key2]

    relative_coordinates.append((xy2[0] - xy1[0], xy2[1] - xy1[1]))

_set = set(relative_coordinates)
counter = collections.Counter(relative_coordinates)
cost = N - counter.most_common()[0][1]
print(cost)

Submission status: Runtime Error

Solution code:
import collections

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

tmp = []
for i in range(N):
    for j in range(N):
        tmp.append((co[i][0]-co[j][0],co[i][1]-co[j][1]))
c = collections.Counter(tmp)
print(N - c.most_common()[1][1])

Submission status: Runtime Error

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

cma_sorted = sorted(cma.items(), key=lambda x:x[1])
print(N - cma_sorted[-1][1])

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
x = []
for i in range(N):
	x.append(list(map(int, input().split())))
L = []
for i in range(N):
	a, b = x[i][0], x[i][1]
	for j in range(N):
		if a > x[j][0] or b > x[j][1]:
			L.append((a - x[j][0], b - x[j][1]))
c = collections.Counter(L)
max = c.most_common(1)[0][1]
print(N - max)

Submission status: Runtime Error

Solution code:

N = int(input())
t = [0] * N
x = [0] * N
for i in range(N):
    t[i], x[i] = map(int, input().split())
p, q = t[0]-t[1], x[0]-x[1]
cost1 = 1
cost2 = 1
for i in range(N-1):
    if t[i+1] !=  (t[i]-p) and x[i+1] != (x[i]-q):
        cost1 += 1
for i in reversed(range(N)):
    if t[i+1] !=  (t[i]-(-p)) and x[i-1] != (x[i]-(-q)) and i != 0:
        cost2 += 1

print(min(cost1, cost2))

Submission status: Runtime Error

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())
total.append([0, x[0], y[0]])
for i in range(1, n):       append(object)
    total.append([x[i]-x[i-1]+y[i]-y[i-1], 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: Runtime Error

Solution code:
n=int(input())
o=[]
for i in range(n):
    x,y=map(int,input().split())
    o.append([x,y])
p2=[]
q2=[]
for i in range(1,n):
    p2+=[int(o[i][0]-o[i-1][0])]
    q2+=[int(o[i][1]-o[i-1][1])]
p1=[int(s) for s in p2]
q1=[int(s) for s in q2]
p1=[abs(s) for s in p1]
q1=[abs(s) for s in q1]
p=min(map(int,p1))
q=min(map(int,q1))
ans=0
a=0
for i in range(n):
    for u in range(n):
        if i==u:
            break
        pd=o[i][0]-o[u][0]
        qd=o[i][1]-o[u][1]
        if pd==p and qd==q:
            a+=1
print(n-a)

Submission status: Runtime Error

Solution code:
n = int(input())

xl = []
for i in range(n):
    x = list(map(int,input().split()))
    xl.append(x)

i = 0
pq = []
for i in range(len(xl)):
    if xl[i][0]-xl[0][0] != 0:
        p = xl[i][0]-xl[0][0]
        q = xl[i][1]-xl[0][1]
        pq += [p,q]

    elif xl[i][1]-xl[0][1] != 0:
        p = xl[i][0]-xl[0][0]
        q = xl[i][1]-xl[0][1]
        pq += [p,q]
        break
    i += 1
    
counts = []
an = []
leng = len(xl)-1

if p > 0 and q > 0:
    for i in range(leng+1):
        count = 0
        k = 0
        for j in range(round(len(pq)/2)):
            an = [xl[leng][0] - pq[0+k] , xl[leng][1] - pq[1+k]]
            if an in xl:
                count += 0
            else:
                count += 1
            k += 2
        counts.append(count)
        leng -= 1
elif p < 0 and q < 0:
    for i in range(leng+1):
        count = 0
        k = 0
        for j in range(round(len(pq)/2)):
            an = [xl[leng][0] + pq[0+k] , xl[leng][1] + pq[1+k]]
            if an in xl:
                count += 0
            else:
                count += 1
            k += 2
        counts.append(count)
        leng -= 1
else p < 0 and q < 0:
    for i in range(leng+1):
        count = 0
        k = 0
        for j in range(round(len(pq)/2)):
            an = [xl[leng][0] - pq[0+k] , xl[leng][1] - pq[1+k]]
            if an in xl:
                count += 0
            else:
                count += 1
            k += 2
        counts.append(count)
        leng -= 1

ls = []
if max(counts) == 0:
    print(1)
else:
    for l in counts:
        if l != 0:
            ls.append(l)
    print(min(ls))

Submission status: Runtime Error

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())
total.append(0, x[0], y[0])
for i in range(1, n):    append()
    total.append([x[i]-x[i-1]+y[i]-y[i-1], 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: Runtime Error

Solution code:
import collections

import math

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


def katamuki(balla, ballb):
    xa, ya = balla
    xb, yb = ballb
    x, y = (xa - xb), (ya - yb)
    dist = math.sqrt(y ** 2 + x ** 2)
    if x == 0:
        return 1000000000, dist
    if y == 0:
        return 0.0, dist
    if y / x == -1.0:
        return 1.0, dist
    return y / x, dist


a = []
for i in range(0, n - 1):
    for j in range(i + 1, n):
        a.append(katamuki(balls[i], balls[j]))

counts = collections.Counter(a)
print(n - max(counts.values()))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

def cost(i,p=100,q=100,s=1,used=set()):
    if len(used)==n:
        return s
    if not used:
        used.add(i)
        x0,y0=xy[i]
        re=[]
        for j in range(n):
            if j==i:continue
            x,y=xy[j]
            used.add(j)
            re+=[cost(j,x-x0,y-y0,1,used)]
            used.remove(j)
        return min(re)
    x0,y0=xy[i]
    re=[]
    for j in range(n):
        if j in used:continue
        x,y=xy[j]
        used.add(j)
        if (x-x0,y-y0)==(p,q):
            re+=[cost(j,p,q,s,used)]
        else:
            re += [cost(j,p,q,s+1,used)]
        used.remove(j)
    return min(re)

n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
mn=100
for i in range(n):
    c=cost(i)
    if c<mn:
        mn=c
print(mn)

Submission status: Runtime Error

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

pqs = {}

for i in range(n):
    for j in range(i + 1, n):
        p = xys[j][0] - xys[i][0]
        q = xys[j][1] - xys[i][1]

        if p == 0 or q == 0:
            continue

        p = max(p, -p)
        q = max(q, -q)

        string = str(p) + " " + str(q)
        if string not in pqs:
            pqs[string] = 0

        pqs[string] += 1


# p, q = map(int, max(pqs.items(), key=lambda x: x[1])[0].split())

print(max(n - max(pqs.values()), 1))

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(input().split())
  a[i][0] = int(a[i][0])
  a[i][1] = int(a[i][1])
d = []
e = []
for i in range(n-1):
  if [a[i+1][0] - a[i][0], a[i+1][1] - a[i][1]] not in d:
    d.append([a[i+1][0] - a[i][0], a[i+1][1] - a[i][1]])
    e.append(1)
  else:
    e[d.index([a[i+1][0] - a[i][0], a[i+1][1] - a[i][1]])] += 1
# f = d[e.index(max(e))]
# p = f[0]
# q = f[1]
print(n-max(e))

Submission status: Runtime Error

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-1):
        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)
    
    return N - max([len(v) for k, v in rem.items()])


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