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:
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())
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:
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 math.inf, 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 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(i+1, N):
    pq.append((xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]))
c = collections.Counter(pq)
ans -= c.most_common()[0][1]
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)
if A==1:
  print(N-1)
else:  
  print(N-A+1)

Submission status: Runtime Error

Solution code:
N = int(input())

a = [list(map(int,input().split())) for _ in range(N)]
def count(a1,a2,n,a):
    count = [0 for i in range(len(a) - n)]
    #print(count)
    x1 = a1[0]
    y1 = a1[1]
    x2 = a2[0]
    y2 = a2[1]
    if x1 != x2:
        #print(1)
        for j in range(len(a)-n):
            #print(a[j][1] - ((y1 - y2)/(x1 - x2))*(a[j][0] - x1) - y1)
            if (a[j][1] - ((y1 - y2)/(x1 - x2))*(a[j][0] - x1) - y1) == 0:
                count[j] += 1
    else:
        for j in range(n,len(a)):
            if a[j][0] == x1:
                count[j] += 1
    if len(count) != 0:
        return max(count)
    else:
        return 0
if N == 1 or N == 2:
    print(1)
    exit()
ans = []
for i in range(N):
    for j in range(i+1,N):
        ans.append(count(a[i],a[j],j+1,a))
        #print(count(a[i],a[j],j+1,a))
print(int(N//2) + 1 - max(ans))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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=[]
for i in range(1,len(balls),1):
  sax = balls[i][0]-balls[i-1][0]
  say = balls[i][1]-balls[i-1][1]
  if [sax,say] not in salist:
    salist.append([sax,say])

balls.reverse()
costs=[]
for i,sa in enumerate(salist):
  cost=1
  for i in range(0,len(balls)-1,1):
    if balls[i+1][0]!=balls[i][0]-sa[0] and balls[i+1][1]!=balls[i][1]-sa[1]:
      cost+=1
  costs.append(cost)

print(min(costs))

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(max(cost1, cost2))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

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(n - max(pqs.items(), key=lambda x: x[1])[1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
l2=[]
sum1=0
sum2=0
sum1,sum2=map(int,input().split())
for i in range(n-1):
    x,y=map(int,input().split())
    c=x-sum1
    c2=y-sum2
    if i==0:
        l.append(c)
        l2.append(c2)
    else:
        if l[i-1]!=c:
            l.append(c)
        if l2[i-1]!=c2:
            l2.append(c2)
    sum1=x
    sum2=y
#print(l,l2)
if max(len(l),max(l2)==1):
    print(1)
else:
    print(max(len(l),len(l2)))

Submission status: Runtime Error

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)

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

Solution code:
from collections import defaultdict
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
c = []
t = defaultdict(int)
for i in range(n):
    for j in range(i+1,n):
        x = s[j][0] - s[i][0]
        y = s[j][1] - s[i][1]
        c.append(str(x) + " " + str(y))
for x in c:
    t[x] += 1

q = list(t.values())
q1 = max(q)
print(n-q1)

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])
b = []
d = []
e = []
dic = {}
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:
from math import Fraction


class PickingUp:
    def __init__(self):
        self.N = int(input())
        self.points = []
        for n in range(self.N):
            self.points.append([int(n) for n in input().split()])

    def main(self):
        pattern_list = []
        for s in range(self.N):
            section_list = []
            for e in range(s + 1, self.N):
                slope = self.__cal_slope(self.points[s], self.points[e])
                for i in range(self.N):
                    section = self.__cal_section(slope, self.points[i])
                    if section not in section_list:
                        section_list.append(section)
                pattern_list.append(len(section_list))

        print(min(pattern_list))

    def __cal_slope(self, s, e):
        if s[0] != e[0]:
            a = Fraction((s[1] - e[1]), (s[0] - e[0]))
            return a
        else:
            return None

    def __cal_section(self, slope, point):
        if slope is not None:
            b = point[1] - slope * point[0]
            return b
        else:
            return point[0]


pickingUp = PickingUp()
pickingUp.main()

Submission status: Runtime Error

Solution code:
N = int(input())
xlist = []
ylist = []
pqlist = []
pqcount = {}
for i in range(N):
  x, y = map(int, input().split(" "))
  xlist.append(x)
  ylist.append(y)

for i in range(N):
  for j in range(i+1, N):
    p = xlist[i] - xlist[j]
    q = ylist[i] - ylist[j]
    tuple_pq = (p, q,)
    if not (tuple_pq in pqlist):
      pqlist.append(tuple_pq)
      pqcount[tuple_pq] = 1
    else:
      pqcount[tuple_pq] += 1

if N == 1:
  print(1)
else:
  print(N - max(pqcount.vzalues()))

Submission status: Runtime Error

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

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        list_.append((abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))

print(N-Counter(list_).most_common()[0][1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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=[]
for i in range(1,len(balls),1):
  sax = balls[i][0]-balls[i-1][0]
  say = balls[i][1]-balls[i-1][1]
  if [sax,say] not in salist:
    salist.append([sax,say])

balls.reverse()
costs=[]
for i,sa in enumerate(reversed(salist)):
  cost=1
  for i in range(0,len(balls)-1,1):
    if balls[i+1][0]!=balls[i][0]-sa[0] and balls[i+1][1]!=balls[i][1]-sa[1]:
      cost+=1
  costs.append(cost)

print(min(costs))

Submission status: Runtime Error

Solution code:

N = int(input())
if N == 2:
    print(1)
else:
    xy = []
    for _ in range(N):
        xy.append(list(map(int, input().split())))

    diff = []
    for i in range(N):
        if i == 0:
            continue
        curr = [xy[i][0]-xy[i-1][0],
                xy[i][1]-xy[i-1][1]]
        diff.append(str(curr[0])+','+str(curr[1]))

    diff_uniq = list(set(diff))
    num = {}
    for curr_target_xy in diff_uniq:
        cnt = 0
        for curr_xy_in_raw_xy in diff:
            if curr_xy_in_raw_xy == curr_target_xy:
                cnt += 1
        num[curr_target_xy] = cnt
    print('{}'.format(N-max(list(num.values()))))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3

from itertools import product
from collections import Counter

def main():
  n = int(input())
  x = []
  y = []

  if n == 1:
    print(1)
    return

  for i in range(n):
    x_tmp, y_tmp = map(int, input().split(' '))
    x.append(x_tmp)
    y.append(y_tmp)

  cnt = Counter()

  for i, j in product(range(n), 2):
    dist = (x[i] - x[j], y[i]- y[j])
    cnt[dist] += 1

  dist, c = cnt.most_common(1)[0]
  print(n - c)

if __name__ == '__main__':
  main()

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)
    index = 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:
            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 defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
list_coord = list()
for i in range(N):
    list_coord.append([int(j) for j in input().split()])
arr_coord = np.array(list_coord)

arr_pat = np.array([])
for i in range(N):
    for j in range(N):
        if i > j:
            arr_pat = np.append(arr_pat, (arr_coord[i] - arr_coord[j]))

arr_pat = arr_pat.reshape(int(len(arr_pat)/2), 2)

arr_pat_uni, arr_pat_cnt = np.unique(arr_pat, axis=0, return_counts=True)

print(N-np.max(arr_pat_cnt))

Submission status: Runtime Error

Solution code:
from itertools import combinations

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

memo = dict()
for (a, b) in combinations(P, 2):
    p, q = a[0] - b[0], a[1] - b[1]
    if p < 0:
        p, q = -p, -q
    elif p == 0 and q < 0:
        q = -q
    if (p, q) in memo:
        memo[(p, q)] += 1
    else:
        memo[(p, q)] = 1

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

Submission status: Runtime Error

Solution code:
from fractions import Fraction


class PickingUp:
    def __init__(self):
        self.N = int(input())
        self.points = []
        for n in range(self.N):
            self.points.append([int(n) for n in input().split()])

    def main(self):
        pattern_list = []
        for s in range(self.N):
            section_list = []
            for e in range(s + 1, self.N):
                slope = self.__cal_slope(self.points[s], self.points[e])
                for i in range(self.N):
                    section = self.__cal_section(slope, self.points[i])
                    if section not in section_list:
                        section_list.append(section)
                pattern_list.append(len(section_list))

        print(min(pattern_list))

    def __cal_slope(self, s, e):
        if s[0] != e[0]:
            a = Fraction((s[1] - e[1]), (s[0] - e[0]))
            return a
        else:
            return None

    def __cal_section(self, slope, point):
        if slope is not None:
            b = point[1] - slope * point[0]
            return b
        else:
            return point[0]


pickingUp = PickingUp()
pickingUp.main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
N = int(input())
balls = []
for i in range(N):
    l = list(map(int,input().split()))	
    balls.append(l)

d = list(itertools.permutations(balls, 2))

#print(d)

dic = {}

for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   dic[str(p) + "," + str(q)] = 0
   
for i in range(len(d)):
   p = d[i][1][0] - d[i][0][0]
   q = d[i][1][1] - d[i][0][1]
   
   dic[str(p) + "," + str(q)] += 1

max_num = max(dic.values())
#p_q = max(dic.items(), key = lambda x:x[1])[0]

#p,q = map(int,p_q.split(","))

#print(max_num)

ans = N - max_num
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
list_coord = list()
for i in range(N):
    list_coord.append([int(i) for i in input().split()])
print(N-max(list_coord))

Submission status: Runtime Error

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

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=[]
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])
  
sa_uniq=[]
for x in salist:
  if x not in sa_uniq:
    sa_uniq.append(x)

balls.reverse()
costs=[]
for i,sa in enumerate(reversed(sa_uniq)):
  cost=1
  for i in range(0,len(balls)-1,1):
    if balls[i+1][0]!=balls[i][0]-sa[0] and balls[i+1][1]!=balls[i][1]-sa[1]:
      cost+=1
  costs.append(cost)

print(min(costs))

Submission status: Runtime Error

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


for i in range(n):
    for j in range(i+1,n):
        l.append([p[j][0]-p[i][0],p[j][1]-p[i][1]])

m=0
for i in range(len(l)):
    cnt=0
    tmp=0
    for j in range(len(l)):
        if l[i][0]==0:
            tmp=l[i][1]
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                if tmp==l[j][1]:
                    acnt+=1
                    if acnt>m:
                        m=acnt
        if l[i][1]==0:
            tmp=l[i][0]
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                if tmp ==l[j][0]:
                    bcnt+=1
                    if bcnt>m:
                        m=bcnt
        if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
            cnt+=1
            if cnt>m:
                m=cnt
        
ans=n
if m!=0:
    ans=n-m-1
if n==2:
    ans=1
print(ans)

Submission status: Runtime Error

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

sa = []
for i, j in xy:
    for k, l in xy:
        sa.append([i - k, j - l])

#sa1
xy.sort()
xy = xy[::-1]
ans = 10000000000000000000
i = 0
while True:
    if i >= len(sa):
        break
    if sa[i] == [0, 0]:
        del sa[i]
        i -= 1
    i += 1


if len(sa) == 0 and n != 0:
    sa = [[xy[0][0] - xy[1][0] + 1, xy[0][1] - xy[1][1] + 1]]
for p, q in sa:
    tmp = 1
    for i in range(1, n):
        x = xy[i][0]
        y = xy[i][1]
        if xy[i - 1][0] == x - p and xy[i - 1][1] == y - q:
            1
        else:
            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):
        x = xy[i][0]
        y = xy[i][1]
        if xy[i - 1][0] == x - p and xy[i - 1][1] == y - q:
            1
        else:
            tmp += 1
    ans = min(ans, tmp)
if len(xy) == 1:
    ans = 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
list_coord = list()
for i in range(N):
    list_coord.append([int(i) for i in input().split()])
print(N-max(list_coord))

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):
    mae = li[li2[i][0]]
    li3.append(mae)
    tugi = li[li2[i+1][0]]
    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[i:]:
            ct += 1
    cl.append(ct)
print(min(cl))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
XY = [[int(i) for i in input().split()]+[j] for j in range(N)]
PQ = []
ans = []

for i,j,k in XY:
    for s,t,u in XY[k+1:]:
        PQ.append([abs(i-s),abs(j-t)])
XY.sort(reverse = True)
xstart = XY[0][0]
ystart = XY[0][1]

for i,j in PQ:
    cost = 1
    xpre = xstart
    ypre = ystart
    for x,y,z in XY[1:]:
        if xpre-x == i and ypre-y == j:
            pass
        else:
            cost += 1
        xpre = x
        ypre = y
    ans.append(cost)
print(min(ans))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

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]
cost = 1
for i in range(N-1):
    if t[i+1] !=  (t[i]-p) and x[i+1] != (x[i]-q):
        cost += 1
print(cost)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter

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:
    zero = Counter(a_list).most_common()[0][1]
    print(n-zero)
else:
    print(1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections
import numpy as np
N = int(input())

balls=[]
for i in range(N):
  XY = list(map(int,input().split()))
  balls.append(np.array(XY))
v=[]
for i in balls:
  for j in balls:
    d = i -j
    if d[0] and d[1] is not 0:
      v.append(str(d))
  #v.append("a")
#print(v)
c = collections.Counter(v)
print(N-c.most_common()[0][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] and b >= x[j][1] and not(a == x[j][0] and b == x[j][1]):
			L.append((a - x[j][0], b - x[j][1]))
c = collections.Counter(L)
max = c.most_common()[0][1]
print(N - max)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import pandas as pd
import statistics as stat

n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]

#print(n)
#print(xy)


df = pd.DataFrame(xy)
df.columns = ['x', 'y']
df['xy'] = df.sum(axis=1)
df2 = df.sort_values(by=['xy'], ascending=True)

x = df2['x'].shift(-1) - df2['x'] 
x2 = stat.mode(x)

y = df2['y'].shift(-1) - df2['y']  
y2 = stat.mode(y)

cst = 1

for i in n-1:
	if x[i] != x2 or y[i] != y2:
		cst += 1

print(cst)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from operator import sub

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
x=[]
y=[]
for i in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)
cost=n
list=[]
for i in range(n):
  for j in range(n):
    if i != j:
      list.append([x[i]-x[j],y[i]-y[j]])
c=Counter(map(tuple, list))
mode=c.most_common(1)
print(cost-mode[0][1])