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:
from collections import Counter
n=int(input())
L=[]
for _ in range(n):
   x,y=map(int,input().split())
   L.append((x,y))
D=[]
for i in range(n):
   for j in range(i+1,n):
         D.append((L[i][0]-L[j][0],L[i][1]-L[j][1]))
         D.append((L[j][0]-L[i][0],L[j][1]-L[i][1]))
C=Counter(D)
print(n-C.most_common()[0][1])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
template <class K, class Hash> struct chash { const size_t RANDOM; const Hash hash; size_t operator()(K key) const { return hash(key) ^ RANDOM; }
  chash() : RANDOM(  (size_t)make_unique<char>().get() ^ (size_t)chrono::high_resolution_clock::now().time_since_epoch().count()  ), hash() { } };
namespace Hashes { struct hash_pii { size_t operator()(pii key) const { return ((size_t)key.ff << 32) | key.ss; } }; }
// HashMap = umap
template <class K, class V, class Hash=hash<K>>
using umap = __gnu_pbds::gp_hash_table<K,V,chash<K,Hash>>;
// HashSet = uset
template <class K, class Hash=hash<K>>
using uset = umap<K, __gnu_pbds::null_type, Hash>;
// oset<K[, Comp]> = Ordered Statistics Set tree
template <class K, class Comp=less<K>>
using oset = __gnu_pbds::tree<K, __gnu_pbds::null_type, Comp, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

class DSU {
  vector<int> p; int c;
  public:
  DSU (int n) : p(n, -1), c(n) { }
  // Get representative of x
  int find(int x) {
    return (p[x] < 0) ? x : p[x] = find(p[x]);
  }
  // Get size of set containg x
  int size(int x) {
    return -p[find(x)];
  }
  // Get # of disjoint sets
  int count() {
    return c;
  }
  // Joins sets containing x, y
  void join(int x, int y) {
    if ((x = find(x)) == (y = find(y))) return;
    if (p[x] < p[y]) swap(x, y);
    p[y] += p[x];
    p[x] = y;
    c--;
  }
};

int deal(vector<pii>& balls, int p, int q) {
  //cerr << "trying: p=" << p << ", q=" << q<<nl;
  const int n = balls.size();
  DSU lines(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      if (balls[i].first + p == balls[j].first) {
        if (balls[i].second + q == balls[j].second) {
          lines.join(i,j);
        }
      }
    }
  }
  return lines.count();
}

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  
  
  
  int n;
  cin >> n;
  
  vector<pair<int,int>> balls(n);
  for(int i = 0; i < n; i++){
    cin >> balls[i].first >> balls[i].second;
  }
  
  int ans = n;

  forx(i, n) {
    forx(j, n) {
      if (i == j) continue;
      int p = balls[i].first - balls[j].first;
      int q = balls[i].second - balls[j].second;
      ans = min(ans, deal(balls, p, q));
    }
  }

  cout << ans << nl;
  
  return 0;
}

Submission status: Runtime Error

Solution code:
def perm_generate(p, a, k=0):
    if k == len(a):
        p.append(a)
    else:
        for i in range(k, len(a)):
            a[k], a[i] = a[i], a[k]
            perm_generate(p, a, k + 1)
            a[k], a[i] = a[i], a[k]


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


def cost_pq(p, q, x, y, perm):
    cost_list = []
    for k in perm:
        cost = 0
        for j in k:
            existed = False
            for i in range(j):
                if x[j] - p == x[i] and y[j] - q == y[i]:
                    existed = True
                    break
            if not existed:
                cost = cost + 1
        cost_list.append((cost, k))
    return min(cost_list)


def min_cost(x, y, perm):
    min_cost_list = []
    for p in range(-max(x), max(x)):
        for q in range(-max(y), max(y)):
            c_pq, k_pq = cost_pq(p, q, x, y, perm)
            min_cost_list.append((c_pq, (p, q, k_pq)))
    return min(min_cost_list)


result = min_cost(x, y, perm)
print(result[0])

Submission status: Runtime Error

Solution code:
from itertools import permutations

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


def cost_pq(p, q, x, y, perm):
    cost_list = []
    for k in perm:
        cost = 0
        for j in k:
            existed = False
            for i in range(j):
                if x[j] - p == x[i] and y[j] - q == y[i]:
                    existed = True
                    break
            if not existed:
                cost = cost + 1
        cost_list.append((cost, k))
    return min(cost_list)


def min_cost(x, y, perm):
    min_cost_list = []
    for p in range(-max(x), max(x)):
        for q in range(-max(y), max(y)):
            c_pq, k_pq = cost_pq(p, q, x, y, perm)
            min_cost_list.append((c_pq, (p, q, k_pq)))
    return min(min_cost_list)


result = min_cost(x, y, perm)
print(result[0])

Submission status: Runtime Error

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

ans = 1
rates = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
        rates[vector] = rates.get(vector, 0) + 1

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

Submission status: Runtime Error

Solution code:
import sys
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)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

from collections import defaultdict  # 初期化済み辞書

def main():
    N = i2n()
    XY = ii2nnn(N)
    # n <= 50 なので、xy[i] → xy[j] の全ての組み合わせについて、距離を全探索できちゃう
    # 距離 dx, dy をkeyに、その距離の i, j ペアの数をvalueとしてカウント
    d = defaultdict(lambda: 0)
    for i in range(N):
        xi, yi = XY[i]
        for j in range(N):
            if i == j:
                continue
            xj, yj = XY[j]
            dxy = (xj - xi, yj - yi)
            d[dxy] += 1
    # 基本はコストN
    # max(value) だけコストを減らせる
    n = N - max(d.values())
    print(n)

main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
x=[]
y=[]
total=[]
count=[]
for _ in range(n):
    x1,y1=map(int,input().split())
    x.append(x1)
    y.append(y1)
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        else:
            temporary=(x[i]-x[j],y[i]-y[j])
            if temporary in total:
                count[total.index(temporary)]=count[total.index(temporary)]+1
            else:
                total.append(temporary)
                count.append(0)
print(n-max(count)-1)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
ret = ()

for i in range(N):
  ret += (tuple([int(_) for _ in raw_input().split(" ")]),)

t = [[0]*N for _ in range(N)]
d = {}
for i in range(N):
  for j in range(i+1, N):    
    x = ret[i][0] - ret[j][0]
    y = ret[i][1] - ret[j][1]
    if not (x,y) in d:
      d[(x,y)] = []
    if not (-x, -y) in d:
      d[(-x, -y)] = []

    d[(x,y)] += [(i,j)]
    d[(-x,-y)] += [(j, i)]

d = [(len(d[_]), _, d[_]) for  _ in d]
d.sort(reverse=True)
d = d[0][2]
ans = [1] * N
current = d[0]
count = 0
while(len(d) > 0):
  count += 1
  current = d[0]
  ans[current[0]] = 0
  ans[current[1]] = 0
  d.remove(current)
  t = [current[0], current[1]]
  c1 = t[0]
  c2 = t[1]

  while(len(d) > 0):
    for i in d:
      if i[1] == c1:
        d.remove(i)
        c1 = i[0]
        ans[c1] = 0
        t = [c1] + t
        break
    else:
      break

  while(len(d) > 0):
    for i in d:
      if c2 == i[0]:
        d.remove(i)
        c2 = i[1]
        ans[c2] = 0
        t = t + [c2]
        break
    else:
      break
  
  #print t
print sum(ans) + count

Submission status: Runtime Error

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

count=0
for i in range(0,N-2):
  tmp = [P[i],P[i+1],P[i+2]]
  tmp.sort()
  if P[i+1]==tmp[1]:
    count+=1

print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
from itertools import permutations

N = int(input())
x, y = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)

# (p, q) = (x_i - x_j, y_i - y_j) を満たす組(i, j)の個数が最大となるように
# p, qを定めればよい
D = Counter(
    (x[i] - x[j], y[i] - y[j])
    for i, j in permutations(range(N), 2)
)
ans = N - max(D.values())

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from itertools import permutations

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]
cnt = defaultdict(int)
for b1, b2 in permutations(balls, 2):
    cnt[(b2[0] - b1[0], b2[1] - b1[1])] += 1
_, n = max(cnt.items(), key=lambda x: x[1])
cost = N - n
print(cost)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from itertools import combinations

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]
cnt = defaultdict(int)
for b1, b2 in combinations(balls, 2):
    cnt[(abs(b2[0] - b1[0]), abs(b2[1] - b1[1]))] += 1
_, n = max(cnt.items(), key=lambda x: x[1])
cost = N - n
print(cost)

Submission status: Runtime Error

Solution code:
import fractions
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
ans = []
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
    count = 0
    for h in range(N):
      for k in range(h+1,N):
        vec2 = [(sheet[k][0]-sheet[h][0]), (sheet[k][1]-sheet[h][1])]
        size = fractions.gcd(vec2[0],vec2[1])
        vec2[0] = vec2[0]//size
        vec2[1] = vec2[1]//size
        if vec == vec2:
          count += 1
    ans += [count]
print(N-max(ans))

Submission status: Runtime Error

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

A.sort()
grid = {}
for i in range(N):
    for j in range(i+1,N):
        if (A[j][0] - A[i][0], A[j][1] - A[i][1]) not in grid:
            grid[A[j][0] - A[i][0], A[j][1] - A[i][1]] = 1
        else:
            grid[A[j][0] - A[i][0], A[j][1] - A[i][1]] += 1

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict

N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
if N == 1:
  print(1)
else:
  d = defaultdict(int)
  for i in range(N):
    xi,yi = xy[i]
    for j in range(N):
      if i==j:
        continue
      else:
        xj,yj = xy[j]
      d[(xj-xi,yj-yi)] += 1
max_v = max(d.values())
print(N-max_v)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
d = defaultdict(int)
for i in range(n):
    xi, yi = z[i]
    for j in range(n):
        if i == j:
            continue
        xj, yj = z[j]
        d[(xi - xj, yi - yj)] += 1
print(n - max(d.values()))

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

N = int(input())
points = []
for i, line in enumerate(sys.stdin):
    x, y = map(int, line.split())
    points.append([x, y])
    if i == N - 1:
        break

counts = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = points[j][0] - points[i][0]
        q = points[j][1] - points[i][1]
        counts.append((p, q))

pq = Counter(counts).most_common()[0][1]
cost = N - pq
print(cost)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

N = int(input())
points = []
for i, line in enumerate(sys.stdin):
    x, y = map(int, line.split())
    points.append([x, y])
    if i == N - 1:
        break

counts = []
for i in range(N - 1):
    p = points[i][0] - points[i+1][0]
    q = points[i][1] - points[i+1][1]
    counts.append((p, q))

pq = Counter(counts).most_common()[0][1]
cost = N - pq
print(cost)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

N = int(input())
points = []
for i, line in enumerate(sys.stdin):
    x, y = map(int, input().split())
    points.append([x, y])
    if i == N:
        break

counts = []
for i in range(N - 1):
    p = points[i][0] - points[i+1][0]
    q = points[i][1] - points[i+1][1]
    counts.append((p, q))

pq = Counter(counts).most_common()[1]
cost = N - pq
print(cost)

Submission status: Runtime Error

Solution code:
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
        x[i],y[i]=list(map(int,input().split()))
diff=[[0,0]for i in range(n-1)]
for i in range(n-1):
        diff[i][0]=x[i+1]-x[i]
        diff[i][1]=y[i+1]-y[i]
ans=[]
for i in range(n-1):
        ans.append(diff.count(diff[i]))
print(n-max(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	xy = []
	for i in range(N):
		x, y = map(int, input().split(" "))
		xy.append((x, y))
		
	re = {}
	for i, val in enumerate(xy):
		x, y = val
		for j, vol in enumerate(xy):
			if i == j:
				continue
			nx, ny = vol
			p = nx - x
			q = ny -y
			if (p, q) in re:
				re[(p, q)] += 1
			else:
				re[(p, q)] = 1
				
	ans = N - max(re.values())
	
	print(ans)
	
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
def solve2():
    N = int(raw_input())
    xy = [None] * N
    for i in range(N):
        xi, yi = [int(_) for _ in raw_input().split()]
        xy[i] = (xi, yi)
    xy.sort()
    dist = []
    for i in range(N):
        for j in range(i+1, N):
            p = xy[j][0] - xy[i][0]
            q = xy[j][1] - xy[i][1]
            dist.append((p,q))
    dist.sort()
    max_cnt = 0
    cnt = 1
    save = dist[0]
    for i in range(1, len(dist)):
        if dist[i] == save:
            cnt += 1
        else:
            max_cnt = max(cnt, max_cnt)
            cnt = 1
            save = dist[i]
    max_cnt = max(cnt, max_cnt)
    print N - max_cnt

if __name__ == '__main__':
    solve2()

Submission status: Runtime Error

Solution code:
from collections import Counter

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

diffs = Counter()
for i in range(N):
    x1, y1 = balls[i]
    for j in range(i+1, N):
        x2, y2 = balls[j]
        diffs.update([(x2-x1, y2-y1)])

ans = N - diffs.most_common(1)[0][1]
print(ans)

Submission status: Runtime Error

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

key_freq = {}
for n in range(N):
    for k in range(n+1,N):
        nx, kx = xs[n], xs[k]
        key = (nx[0]-kx[0], nx[1]-kx[1])
        if key_freq.get(key) is None:
            key_freq[key] = 0
        key_freq[key] += 1
key_freq = sorted([(key,freq) for key, freq in key_freq.items()],key=lambda x:x[1])[-1]

key = key_freq[0]
x_n ={}
for x in xs:
    x_n[tuple(x)] = (x[0] - key[0],x[1]-key[1])
c=0
for x, n in x_n.items():
    if n in x_n:
        c+=0
    else:
        c+=1
print(c)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
def inpl(): return list(map(int, input().split()))

N = int(input())
XY = sorted([inpl() for _ in range(N)])
D = defaultdict(int)
for i in range(N):
    for j in range(i+1, N):
        D[(XY[j][0] - XY[i][0]), (XY[j][1] - XY[i][1])] += 1
print(N - max(D.values()))

Submission status: Runtime Error

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

li2 = [(x[0]-y[0],x[1]-y[1]) for x in li for y in li]
data = list(set(li2)) #かぶりを消すような作業や、カウントする前はsetがよい
data.remove((0,0))
data2 = tuple(data) #forなどでlistの中身をたくさん参照する場合はtupleがよい
qty = list(map(lambda x: li2.count(x),data2))

print(n-max(qty))

Submission status: Runtime Error

Solution code:
#XY = [[1,1],[1,2],[2,2],[2,1]]
#N = len(XY)
if N==1:
    print(1)
    exit()
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)

Submission status: Runtime Error

Solution code:
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)

Submission status: Runtime Error

Solution code:
#XY = [[1,1],[1,2],[2,2],[2,1]]
#N = len(XY)
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0])
print(N-d)

Submission status: Runtime Error

Solution code:
from collections import namedtuple, Counter

Point = namedtuple('Point', 'x y')
N = int(input())
P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append(Point(x, y))
sx = sorted(P, key=lambda p: p.x)
sy = sorted(P, key=lambda p: p.y)


def solve(a):
    diff_x = [j.x - i.x for i, j in zip(a, a[1:])]
    diff_y = [j.y - i.y for i, j in zip(a, a[1:])]
    x_common = Counter(diff_x).most_common()
    y_common = Counter(diff_y).most_common()
    if x_common[0][0] == y_common[0][0] == 0:
        if x_common[0][1] >= y_common[0][1]:
            p, q = x_common[0][0], y_common[1][0]
        else:
            p, q = x_common[0][1], y_common[0][0]
    else:
        p, q = x_common[0][0], y_common[0][0]
    cost = 1
    prev = a[0]
    for e in a[1:]:
        if not (e.x - p == prev.x and e.y - q == prev.y):
            cost += 1
        prev = e
    return cost


print(min(solve(sx), solve(sy)))

Submission status: Runtime Error

Solution code:
#XY = [[1,2],[1,1],[2,2],[2,1],[3,1],[3,2]]
#N = len(XY)
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0]/2)
print(N-d)

Submission status: Runtime Error

Solution code:
#XY = [[1,2],[1,1],[2,2],[2,1],[3,1],[3,2]]
#N = len(XY)
N=int(input())
XY =  [list(map(int, input().split())) for _ in range(N)]
vecs = [  (x[0]-y[0], x[1]-y[1]) for y in XY   for x in XY]
pattern = list(set(vecs))
pattern.remove((0,0))
pattern2 = tuple(pattern)
qty = map(lambda x: vecs.count(x), pattern2)
data = zip(qty, pattern)
data2 = list(data)
data2.sort()
d = int(data2[-1][0]/2)
N-d

Submission status: Runtime Error

Solution code:
from collections import namedtuple, Counter

Point = namedtuple('Point', 'x y')
N = int(input())
P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append(Point(x, y))
sx = sorted(P, key=lambda p: p.x)
sy = sorted(P, key=lambda p: p.y)


def solve(a):
    diff_x = [j.x - i.x for i, j in zip(a, a[1:])]
    diff_y = [j.y - i.y for i, j in zip(a, a[1:])]
    x_common = Counter(diff_x).most_common(2)
    y_common = Counter(diff_y).most_common(2)
    if x_common[0][0] == y_common[0][0] == 0:
        if x_common[0][1] >= y_common[0][1]:
            p, q = x_coomon[0][0], y_common[1][0]
        else:
            p, q = x_coomon[0][1], y_common[0][0]
    else:
        p, q = x_common[0][0], y_common[0][0]
    cost = 1
    prev = a[0]
    for e in a[1:]:
        if not (e.x - p == prev.x and e.y - q == prev.y):
            cost += 1
        prev = e
    return cost


print(min(solve(sx), solve(sy)))

Submission status: Runtime Error

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
pq={}
for i in range(n):
    x,y=xy[i]
    for j in range(n):
        if j==i:continue
        xx,yy=xy[j]
        p=xx-x
        q=yy-y
        pq.setdefault((p,q),0)
        pq[(p,q)]+=1
print(n-max(pq.values()))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np


def main():
    n = int(input())
    balls = [[int(e) for e in input().split()] for _ in range(n)]
    diff = {}
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if ((balls[i][0] - balls[j][0]), (balls[i][1] - balls[j][1])) in diff:
                diff[((balls[i][0] - balls[j][0]), (balls[i][1] - balls[j][1]))] += 1
            else:
                diff[((balls[i][0] - balls[j][0]), (balls[i][1] - balls[j][1]))] = 1
    print(n - max(diff.values()))


main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n=int(input())
b=[]
for i in range(n):
    x,y=map(int,input().split())
    b.append((x,y))
C=defaultdict(int)
for i in range(n):
    for j in range(i+1,n):
        p,q=b[i][0]-b[j][0],b[i][1]-b[j][1]
        C[(p,q)]+=1
        C[(-p,-q)]+=1

l=[]
for i in C.items():
    l.append(i)
l.sort(key=lambda x:x[1],reverse=True)
print(n-l[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
xy = [tuple([int(_) for _ in input().split()]) for i in range(n)]
if n == 1:                                                     range(stop)
    result = 1
else:
    xy.sort()
    dxy = [(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
           for i in range(n)
           for j in range(i+1, n)]
    cdxy = Counter(dxy)
    result = n - max(cdxy.values())
print(result)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
xy = [tuple([int(_) for _ in input().split()]) for i in range(N)]
if n == 1:
    result = 1
else:
    xy.sort()
    dxy = [(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
           for i in range(N)
           for j in range(i+1, N)]
    cdxy = Counter(dxy)
    result = N - max(cdxy.values())
print(result)

Submission status: Runtime Error

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

dxy = [
    (XY[i][0] - XY[j][0], XY[i][1] - XY[j][1])
    for i in range(N)
    for j in range(i + 1, N)
]

from collections import Counter

cdxy = Counter(dxy)

m = max(cdxy.values())

#print(XY)
#print(dxy)
#print(cdxy)

result = N - m
print(result)

Submission status: Runtime Error

Solution code:
n = int(input())
if n <= 2:
    print( 1)
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

points.sort()
dictpq = {}
for i in range(n):
    for j in range(i+1,n):
        p = points[i][0] - points[j][0]
        q = points[i][1] - points[j][1]
        if (p,q) in dictpq:
            dictpq[(p,q)] +=1
        else:
            dictpq[(p,q)] =1
print(n-max(dictpq.values()))

Submission status: Runtime Error

Solution code:
x = input()
(N, K) = (int(x[0]), int(x[2]))
max_distribution = N - K
if K == 1:
    max_distribution = 0
print(max_distribution)

Submission status: Runtime Error

Solution code:
n = int(input())
if n <= 2:
    print( 1)
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

points.sort()
while len(points) != 0:
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    #print(p, " ", q)
    while len(points) != 0 and xn >= points[-1][0] and yn >= points[-1][1]:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
print(cost)

Submission status: Runtime Error

Solution code:
n = int(input())
if n <= 2:
    print( 1)
cost = 0
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

points.sort()
while len(points) != 0:
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    #print(p, " ", q)
    while len(points) != 0:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
        else:
            break

print(cost)

Submission status: Runtime Error

Solution code:
n = int(input())
cost = 0
points = []
for i in range(n):
    xy = input().split()
    x = int(xy[0])
    y = int(xy[1])
    points.append((x,y))
points.sort()
while len(points) != 0:
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    print(p, " ", q)
    while len(points) != 0:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
        else:
            break

print(cost)

Submission status: Runtime Error

Solution code:
n = int(input())
cost = 0
points = []
for i in range(n):
    xy = input().split()
    x = int(xy[0])
    y = int(xy[1])
    points.append((x,y))

while len(points) != 0:
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    #print(p, " ", q)
    while len(points) != 0:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
        else:
            break

print(cost)

Submission status: Runtime Error

Solution code:
import sys
data = sys.stdin.readlines()
n = int(data[0])
cost = 0
points = []
for i in range(n):
    xy = data[i+1].split()
    x = int(xy[0])
    y = int(xy[1])
    points.append((x,y))

while len(points) != 0:
    p = points[-1][0] - points[-2][0]
    q = points[-1][1] - points[-2][1]
    xn = points[-1][0] - p
    yn = points[-1][1] - q
    cost +=1
    points.pop()
    #print(p, " ", q)
    while len(points) != 0:
        if points[-1][0] == xn and points[-1][1] == yn:
            xn = points[-1][0] - p
            yn = points[-1][1] - q
            points.pop()
        else:
            break

print(cost)

Submission status: Runtime Error

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

xy_list.sort(key=lambda x:(x[0],x[1]))
    
diff_dict = {}
for i in range(N-1):
    for j in range(i+1,N):
        dx = xy_list[j][0] - xy_list[i][0]
        dy = xy_list[j][1] - xy_list[i][1]
        
        if (dx,dy) in diff_dict:
            diff_dict[(dx,dy)] += 1
        else:
            diff_dict[(dx,dy)] = 1
            

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

Submission status: Runtime Error

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

xy_list.sort(key=lambda x:(x[0],x[1]))

xy_list

diff_dict = {}
for i in range(N-1):
    for j in range(i+1,N):
        dx = xy_list[j][0] - xy_list[i][0]
        dy = xy_list[j][1] - xy_list[i][1]
        
        if (dx,dy) in diff_dict:
            diff_dict[(dx,dy)] += 1
        else:
            diff_dict[(dx,dy)] = 1
            

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

b = []
for a1, a2 in zip(a[1:], a[:-1]):
    b.append((a1[0] - a2[0], a1[1] - a2[1]))

c = Counter(b)
cc = c.most_common()

print(n - cc[0][1])

Submission status: Runtime Error

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

#print(n)
print(xy)
#print(xy[0][1])

vec = []
vec2 = []

for i in range(n):
	for j in range(i + 1, n):
		x = xy[i][0] - xy[j][0]
		y = xy[i][1] - xy[j][1]
		z = [x, y]
		if z not in vec:
			vec.append(z)
		vec2.append(z)        

#print(vec)
#print(vec2)

#vec2 = list(set(vec))

cnt = 0
idx = 0

for i, x  in enumerate(vec):
	if cnt < vec2.count(x):
		cnt = vec2.count(x)
		idx = i

#print(cnt)
#print(idx)

pq = vec[idx]

print(pq)
#print(pq[0])
#print(pq[1])

cst = 0

for i in range(n):
	pq_x = xy[i][0] - pq[0]
	pq_y = xy[i][1] - pq[1]
	pq_xy = [pq_x, pq_y]
	#pq_sub_x = xy[i][0] - pq[0]
	#pq_sub_y = xy[i][1] - pq[1]
	#pq_sub = [pq_sub_x, pq_sub_y]
	if pq_xy not in xy:
		#if pq_sub not in xy:
		cst += 1

print(cst)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
xy = [tuple(map(int,input().split())) for i in range(N)]
xy.sort( key = lambda x: (x[0],x[1]))
l = []
for i in range(N):
    for j in range(i+1,N):
        (x_diff, y_diff) = [xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]]
        l.append((x_diff, y_diff))
dic = collections.Counter(l)
val = dic.values()
print(N - max(val))