Problem:


Score : 300 points

Problem Statement

There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).

We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation:

Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.

Find the minimum total cost required to collect all the balls when we optimally choose p and q.

Constraints

1 \leq N \leq 50

|x_i|, |y_i| \leq 10^9

If i \neq j, x_i \neq x_j or y_i \neq y_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum total cost required to collect all the balls.

Sample Input 1

2
1 1
2 2

Sample Output 1

1

If we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).

Sample Input 2

3
1 4
4 6
7 8

Sample Output 2

1

If we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).

Sample Input 3

4
1 1
1 2
2 1
2 2

Sample Output 3

2



Sample input:
2
1 1
2 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
N = int(input())
X, Y = [], []
XY = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append((x, y))

D = []
for i in range(1,N):
    D.append((XY[i][0] - XY[i - 1][0], XY[i][1] - XY[i - 1][1]))

DS = list(set(D))

cnt = 0
for d in DS:
    cnt = max(cnt, D.count(d))

res = N - cnt


XY.sort()
D = []
for i in range(1,N):
    D.append((XY[i][0] - XY[i - 1][0], XY[i][1] - XY[i - 1][1]))

DS = list(set(D))

cnt = 0
for d in DS:
    cnt = max(cnt, D.count(d))

res = min(res, N - cnt)

XY.sort(key=lambda x: x[1])
D = []
for i in range(1,N):
    D.append((XY[i][0] - XY[i - 1][0], XY[i][1] - XY[i - 1][1]))

DS = list(set(D))

cnt = 0
for d in DS:
    cnt = max(cnt, D.count(d))

res = min(res, N-cnt)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
arr = []

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

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

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

C = []
for i in range(N):
    for j in range(N):
        if i < j:
            x = arr[i][0]-arr[j][0]
            y = arr[i][1]-arr[j][1]
            C.append([x, y])


C = get_unique_list(C)
S = [0 for i in range(len(C))]

for c in range(len(C)):
    tmp = [[arr[0][0], arr[0][1]]]
    for i in range(1, N):
        l = len(tmp)
        for j in range(l):
            x_t = tmp[j][0] - arr[i][0]
            y_t = tmp[j][1] - arr[i][1]
            arr_i = [arr[i][0], arr[i][1]]
            if C[c][0] == 0 and y_t%C[c][1] == 0:
                if x_t == 0:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)

            elif C[c][1] == 0 and x_t%C[c][0] == 0:
                if y_t == 0:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)
            else:
                if x_t*C[c][1] == y_t*C[c][0]:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)
                    
    S[c] = len(tmp)

print(min(S))

Submission status: Wrong Answer

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

if n <= 2:
    print(1)

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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(len(d)):
    if max < d.count(d[i])+d.count(d[i]*(-1)):
        max = d.count(d[i])+d.count(d[i]*(-1))

if max == N:
    max = N-1

print(N-max)

Submission status: Wrong Answer

Solution code:
N=int(input())
point=[]
merge=0
for i in range(0,N):
    x,y=map(int,input().split())
    point.append([x,y])
p=0
q=0
point.sort()
ans=0
if(N>1):
    for i in range(0,N-1):
        for j in range(i+1,N):
            p=point[j][0]-point[i][0]
            q=point[j][1]-point[i][1]
            merge=0
        for k in range(0,N):
            if([point[k][0]+p,point[k][1]+q] in point):
                merge+=1
        ans=max(ans,merge)
        print(N-ans)
else:
    print(N)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy_array = [[int(x) for x in input().split()] for y in range(n)]
xy_array = sorted(xy_array, key=lambda x: (x[0], x[1]))

a_array = []
tmp_x, tmp_y = xy_array[0]
for x, y in xy_array[1:]:
    a_array.append([tmp_x - x, tmp_y - y])
    tmp_x, tmp_y = x, y

res = float("inf")
for ax, ay in a_array:
    if ax == 0 or ay == 0:
        continue
    tmp_res = 1
    now_x, now_y = xy_array[-1]
    if now_x - ax == 0 or now_y - ay == 0:
        continue
    for x, y in reversed(xy_array[:-1]):
        if now_x + ax == x and now_y + ay == y:
            pass
        else:
            tmp_res += 1
        now_x, now_y = x, y
    res = min(res, tmp_res)

xy_array = sorted(xy_array, key=lambda x: (x[1], x[0]))
a_array = []
tmp_x, tmp_y = xy_array[0]
for x, y in xy_array[1:]:
    a_array.append([tmp_x - x, tmp_y - y])
    tmp_x, tmp_y = x, y

for ax, ay in a_array:
    tmp_res = 1
    now_x, now_y = xy_array[-1]
    if now_x - ax == 0 or now_y - ay == 0:
        continue
    for x, y in reversed(xy_array[:-1]):
        if now_x + ax == x and now_y + ay == y:
            pass
        else:
            tmp_res += 1
        now_x, now_y = x, y
    res = min(res, tmp_res)
print(res if res != float("inf") else n if n ==1 else n-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda x:x[0])
XY.sort(key=lambda x:x[1])
#print(XY)

diffs = []
for i in range(1, N):
    dx = XY[i][0] - XY[0][0]
    dy = XY[i][1] - XY[0][1]
    diffs.append((dx, dy))

ans = 0
for diff in diffs:
    cnt = 0
    dx, dy = diff
    #print(dx,dy)
    for i in range(N):
        x = XY[i][0]; y = XY[i][0]
        if (x+dx, y+dy) in XY:
            cnt += 1
    ans = max(ans, cnt)
print(N-ans)

Submission status: Wrong Answer

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 = []
if n == 1:
    print(1)
else:
    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]]
        j = i
        if bbb == ccc:
            while j > 1:
                j -= 1
                if ccc == li2[j][1]:
                    continue
                else:
                    dif.append([tugi[0] - li[li2[j][0]][0], tugi[1] - li[li2[j][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: Wrong Answer

Solution code:
import collections
N = int(input())
if N == 1:
    print("1")
elif N == 2:
    print("1")
else:
    L = []
    for i in range(N):
        [x, y] = map(int, input().split())
        L.append([y, x])
    L.sort()
    
    
    
    difL = []
    for i in range(N-1):
        [difx, dify] = L[i+1][0]-L[i][0], L[i+1][1]-L[i][1]
        difL.append([difx, dify])

    t = map(tuple, difL)
    counted = collections.Counter(t)
    print(N-counted.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from copy import copy

N = int(input())
xy = []
maxSameLine = 0


def howManySameLines(idomae, idoato, xy):
    sameLine = 0
    p = idoato[0] - idomae[0]
    q = idoato[1] - idomae[1]
    for point in xy:
        if (point[0] == (idoato[0] + p)) and (point[1] == (idoato[1] + q)):
            sameLine += 1

    return sameLine


for _ in range(N):
    xy.append(list(map(int, input().split(" "))))

for idxp in range(len(xy)):
    points = copy(xy)
    idomae = points.pop(idxp)
    for idxq in range(len(xy)-1):
        idoato = points.pop()
        sameLine = howManySameLines(idomae, idoato, points)

        if sameLine > maxSameLine:
            maxSameLine = sameLine

print(len(xy)-maxSameLine)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    for i in range(N):
        for j in range(i+1, N):
            p = xy[j][0] - xy[i][0]
            q = xy[j][1] - xy[i][1]
            _gcd = gcd(p,q)
            # print "i = " + str(i) + ", j = " + str(j)
            # print p, q, _gcd
            p = p / _gcd
            q = q / _gcd
            AddToPQSet(((p,q),i,j))

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

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
balls=deque(sorted([[int(i) for i in input().split()] for _ in range(n)],key=lambda x:x[0]))
MAX=0
for i,(x0,y0) in enumerate(balls):
    for j,(x1,y1) in enumerate(balls):
        if j==i:
            continue
        else:
            cnt=1
            dis=(x1-x0)**2+(y1-y0)**2
            if x1==x0:
                for h,(x2,y2) in enumerate(balls):
                    if h!=i:
                        if x2==x1:
                            cnt+=1
            elif y1==y0:
                for h,(x2,y2) in enumerate(balls):
                    if h!=i:
                        if y2==y1:
                            cnt+=1
            else:
                a=(y1-y0)/(x1-x0)
                b=y1-x1*a
                for h,(x2,y2) in enumerate(balls):
                    if h!=i:
                        if y2==a*x2+b:
                            cnt+=1
        if MAX<cnt:
            MAX=cnt
print(len(balls)-MAX+1 if len(balls)-MAX==0 else len(balls)-MAX)

Submission status: Wrong Answer

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

X=0 if X==1 else X
Y=0 if Y==1 else Y
print(max(N-X,N-Y))

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
if N<=2:
  print(1)
else:
  ans=N
  for i,j in itertools.combinations(range(N),2):
      LL=L[:]
      kans=N
      p,q=L[j][0]-L[i][0],L[j][1]-L[i][1]
      a=1 if p>=0 else -1
      b=1 if q>=0 else -1
      x,y=L[i][0],L[i][1]
      
      LL.sort(key=lambda x:(x[0]*a,x[1]*b))
      k=0
      while k<len(LL)-1 and len(LL)>=2:
        c=0
        if p==0:
          if (LL[-1][1]-LL[k][1])%q==0:
            c=1
        elif q==0:
          if (LL[-1][0]-LL[k][0])%p==0:
            c=1
        else:
          if (LL[-1][1]-LL[k][1])%q==0 and (LL[-1][0]-LL[k][0])%p==0:
            c=1
        if c==1:
          LL.pop()
          k=0
          kans-=1
          continue
        k+=1
        if k>=len(LL)-1:
          LL.pop()
          k=0
          continue
      print(p,q,kans)
      ans=min(ans,kans)
  print(ans)

Submission status: Wrong Answer

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

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

pena_x = cost_x.count(0)
pena_y = cost_y.count(0)
cost_x = list(set(cost_x))
cost_y = list(set(cost_y))
cost = max(len(cost_x)+pena_x-1,len(cost_y)+pena_y-1)

print(cost)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
h = defaultdict(int)
for x, y in xy:
    h[(x, y)] = True
mx, my = xy[-1]
d = defaultdict(int)
ans = 10**10
for i in range(n):
    x1, y1 = xy[i]
    for j in range(i+1, n):
        x2, y2 = xy[i+1]
        z1 = x2-x1
        z2 = y2-y1

        t = set()
        k = 0
        a = 0
        while k < n and len(t) < n:
            xk, yk = xy[k]
            if (xk, yk) not in t:
                a += 1
                t.add((xk, yk))
                while xk <= mx and yk <= my:
                    if (xk+z1, yk+z2) in h:
                        t.add((xk+z1, yk+z2))
                    xk += z1
                    yk += z2
            k += 1
        a += n-len(t)
        if a < ans:
            ans = a

print(ans)

Submission status: Wrong Answer

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 = collections.Counter(relative_coordinates)
# cost = N - counter.most_common()[0][1]
cost = 1
print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
cst_p = 1
cst_q = 1
mincst_p = float("inf")
mincst_q = float("inf")
xy.sort(key = lambda x:x[0])
keep = xy[0]
if N != 1:
    for j in range(N-1):
        p = xy[j+1][0]-xy[j][0]
        q = xy[j+1][1]-xy[j][1]
        for i in range(1,N-1):
            if not(xy[i][0] == keep[0]+p and xy[i][1] == keep[1]+q):
                cst_p += 1
                keep = xy[i]
            else:
                keep = xy[i]
        if not(xy[N-1][0] == keep[0]+p and xy[N-1][1] == keep[1]+q):
            cst_p+= 1
        if mincst_p > cst_p:
            mincst_p = cst_p
        cst_p = 1 
else:
    print(1)
    exit()
 
xy.sort(key = lambda x:x[1])
keep = xy[0]
if N != 1:
    for j in range(N-1):
        p = xy[j+1][0]-xy[j][0]
        q = xy[j+1][1]-xy[j][1]
        for i in range(1,N-1):
            if not(xy[i][0] == keep[0]+p and xy[i][1] == keep[1]+q):
                cst_q+= 1
                keep = xy[i]
            else:
                keep = xy[i]
        if not(xy[N-1][0] == keep[0]+p and xy[N-1][1] == keep[1]+q):
            cst_q += 1
        if mincst_q > cst_q:
            mincst_q = cst_q
        cst_q = 1
else:
    print(1)
    exit()
 
print(min(mincst_p,mincst_q))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import functools
import itertools

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

D = defaultdict(list)
for p1, p2 in itertools.combinations(P, 2):
    d = (p1[0] - p2[0], p1[1] - p2[1])
    if d[0] == 0 and d[1] == 0:
        continue
    elif d[0] == 0:
        d = (0, abs(d[1]))
    elif d[0] < 0:
        d = (-d[0], -d[1])
    for S in D[d]:
        if p1 in S:
            S.add(p2)
            break
        elif p2 in S:
            S.add(p1)
            break
    else:
        D[d].append({p1, p2})

ans = 100
for L in D.values():
    ans = min(ans, len(L) + N - functools.reduce(lambda x, S: x + len(S), L, 0))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
arr = []

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

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

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

C = []
for i in range(N):
    for j in range(N):
        if i < j:
            x = arr[i][0]-arr[j][0]
            y = arr[i][1]-arr[j][1]
            C.append([x, y])


C = get_unique_list(C)
S = [0 for i in range(len(C))]

for c in range(len(C)):
    tmp = [[arr[0][0], arr[0][1]]]
    for i in range(1, N):
        l = len(tmp)
        for j in range(l):
            x_t = tmp[j][0] - arr[i][0]
            y_t = tmp[j][1] - arr[i][1]
            arr_i = [arr[i][0], arr[i][1]]
            if C[c][0] == 0 and y_t%C[c][1] == 0:
                if x_t == 0:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)

            elif C[c][1] == 0 and x_t%C[c][0]:
                if y_t == 0:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)
            else:
                if x_t*C[c][1] == y_t*C[c][0]:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)
                    
    S[c] = len(tmp)

print(min(S))

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 1
max = -99999
ruiseki_x = []
ruiseki_y = []
list_x = []
list_y = []
sort_list = []
for i in range(N):
    x,y = map(int,input().split())
    list_x.append(x)
    list_y.append(y)
for i in range(1,N):
    ruiseki_x.append(list_x[i-1] - list_x[i])
    ruiseki_y.append(list_y[i-1] - list_y[i])
c = list(zip(ruiseki_x,ruiseki_y))
count = 0
for i in range(len(c)):
    count = 0
    for j in range(len(c)):
        if c[i] == c[j]:
            count += 1
    if max < count:
        max = count
print(len(c) - max + 1)

Submission status: Wrong Answer

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

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

cross = []

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

res = 0
ans = []

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

print(N - reduce)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = x[0]
b = y[0]

minCost =1000000
for p in range(n):
  for q in range(n):
      cost = 0
      chokuzenX = 0
      chokuzenY = 0
      flag=1
      for i in range(n):
          if flag==1:
              chokuzenX = x[i]
              chokuzenY = y[i]
              flag=0
              cost +=1
          else:
              if a-p == chokuzenX and b-q == chokuzenY:
                  continue
              else:
                  cost +=1
      if minCost < cost:
          minCost = minCost
      else:
          minCost = cost

print(minCost)

Submission status: Wrong Answer

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


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

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


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
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)
if N == 1:
    print(1)
    sys.exit()
    

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(0) + "," + str(0)] = -1


max_num = max(dic.values())
ans = N - max_num
p_q = max(dic.items(), key = lambda x:x[1])[0]
p,q = map(int,p_q.split(","))

#if p == 0 && q == 0:
    
#print(max_num)


print(ans)

Submission status: Wrong Answer

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

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

    for i in range(N):
        for j in range(i+1, N):
            p = xy[j][0] - xy[i][0]
            q = xy[j][1] - xy[i][1]
            _gcd = gcd(p,q)
            # print "i = " + str(i) + ", j = " + str(j)
            # print p, q, _gcd
            p = p / _gcd
            q = q / _gcd
            AddToPQSet(((p,q),i,j))

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

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import itertools
import collections

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

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

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

Submission status: Wrong Answer

Solution code:
import math
import copy

N = int(input())

ball = [0] * N

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

ans = N - 1
pq = []

# p,q の組
for i in range(N) :
    for j in range(N) :
        p = ball[j][0] - ball[i][0]
        q = ball[j][1] - ball[i][1]

        if p == 0 and q == 0 :
            continue
        pq.append((p,q))

ans = N - 1

for p , q in pq :
    check = [0] * N
    count = 0

    for i in range(N) :
        if check[i] == 0 :
            check[i] = 1
            count += 1
            for j in range(1,N) : # 上
                if [ball[i][0] - j * p , ball[i][1] - j * q] in ball :
                    index = ball.index([ball[i][0] - j * p , ball[i][1] - j * q])
                    check[index] = 1
                else :
                    break
            for j in range(1,N) : # 下
                if [ball[i][0] + j * p , ball[i][1] + j * q] in ball :
                    index = ball.index([ball[i][0] + j * p , ball[i][1] + j * q])
                    check[index] = 1
                else :
                    break

    ans = min(ans,count)


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
point=[]
merge=0
for i in range(0,N):
    x,y=map(int,input().split())
    point.append([x,y])
p=0
q=0
point.sort()
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        p=point[j][0]-point[i][0]
        q=point[j][1]-point[i][1]
        merge=0
    for k in range(0,N):
        if([point[k][0]+p,point[k][1]+q] in point):
            merge+=1
    ans=max(ans,merge)
print(N-ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
#
# xy.sort()
# xy = xy[::-1]
# sa = []
# for i in range(1, n):
#     sa.append([xy[i - 1][0] - xy[i][0], xy[i - 1][1] - xy[i][1]])
#
# xy.sort(key=lambda x:x[1])
# xy2 = xy
# print(xy2)
# xy2 = xy2[::-1]
# sa2 = []
# for i in range(1, n):
#     sa2.append([xy[i - 1][0] - xy[i][0], xy[i - 1][1] - xy[i][1]])
# print(sa, sa2)

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


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: Wrong Answer

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