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 = []
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
      for i in range(n):
          if n==0:
              chokuzenX = x[i]
              chokuzenY = y[i]
              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:
import fractions
N = int(input())
sheet = []
for i in range(N):
  line = input().split()
  sheet+=[(int(line[0]), int(line[1]))]
dic = {}
for i in range(N):
  start = sheet[i]
  for j in range(i+1, N):
    vec = [(sheet[j][0]-start[0]), (sheet[j][1]-start[1])]
    size = fractions.gcd(vec[0],vec[1])
    vec[0] = vec[0]//size
    vec[1] = vec[1]//size
    if vec[0]<0 and vec[1]<0:
      vec[0] = (-1)*vec[0]
      vec[1] = (-1)*vec[1]
    vec = tuple(vec)
    if vec not in dic.keys():
      dic[vec] = set([j])
    else:
      dic[vec].add(j)
m = 0
for s in dic.values():
  if len(s)>m:
    m = len(s)
print(N-m)

Submission status: Wrong Answer

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


mincost = 10000000

for j,a in enumerate(xy): #O(N)
    for k, b in enumerate(xy[j+1:]):
        p = a[0]-b[0]
        q = a[1]-b[1]
        prev = a
        check = [0]*N
        check[j] = 1
        check[k] = 1
        cost = 1
        flag = True
        while flag:
            for i, c in enumerate(xy):
                if ([prev[0]-p,prev[1]-q]==c):
                    check[i] = 1
                    prev = c

            for i in range(N):
                if (not check[i]):
                    prev = xy[i]
                    check[i] = 1
                    cost += 1
                    break
                flag = False
        mincost = min(cost, mincost)   

print(mincost)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, x: "List[int]", y: "List[int]"):
    # rted(a, key=lambda x:x[1], reverse=True)

    a = [[x[i],y[i]] for i in range(N)]

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

    x.sort()
    y.sort()

    from collections import Counter

    csx = Counter([abs(x[i+1]-x[i]) for i in range(N-1)])
    csy = Counter([abs(y[i+1]-y[i]) for i in range(N-1)])

    p = [i for i,v in csx.most_common()] + [-1*i for i,v in csx.most_common()]
    q = [i for i,v in csy.most_common()] + [-1*i for i,v in csy.most_common()]
    p.sort()
    q.sort()

    a = sorted(a, key=lambda x:(x[1],x[0]), reverse=True)
    ans = 10000000000
    for i in p:
        for j in q:
            if(i == 0 and j == 0):
                continue
            
            tans = 1
            r = 0
            for k in range(1,N):
                s,t = a[k]
                if(s == r and i != 0):
                    continue
                else:
                    r = s
                if(a[k-1][0] == s-i and a[k-1][1] == t-j):
                    continue
                else:
                    tans += 1
            ans = min(ans,tans)

    a = sorted(a, key=lambda x:(x[0],x[1]), reverse=True)
    for i in p:
        for j in q:
            if(i == 0 and j == 0):
                continue
            tans = 1
            r = 0
            for k in range(1,N):
                s,t = a[k]
                if(s == r and i != 0):
                    continue
                else:
                    r = s
                if(a[k-1][0] == s-i and a[k-1][1] == t-j):
                    continue
                else:
                    tans += 1
            ans = min(ans,tans)




    print(ans)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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],p[i][0],p[i][1]])

m=0
for i in range(len(l)):
    cnt=0
    for j in range(len(l)):
        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-1
if m!=0:
    ans=n-m-1
if n==2:
    ans=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
l2 = []

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

for i in range(len(l)):
    for j in range(i+1, len(l)):
        dif1 = l[i][0] - l[j][0]
        dif2 = l[i][1] - l[j][1]
        if dif1 == 0 and dif2 == 0:
            continue
        l2.append(str(dif1) + ' ' + str(dif2))
##print(l2)

try:
    cnt = l2.count(max(l2, key=l2.count))
except:
    cnt = 0
    
print(n - cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
import statistics
import math
from collections import Counter
N=int(input())
x=[]
y=[]
for a in range(N):
    b,c=(int(x) for x in input().split())
    x.append(b)
    y.append(c)
sa=deque([[0,0]])
if N>1:
    for a in range(N):
        for b in range(N-a-1):
            sx=abs(x[a]-x[a+b+1])
            sy=abs(y[a]-y[a+b+1])
            sa.append([sx,sy])
    sa.remove([0,0])
    ans=[]
    nagasa=len(sa)
    for a in range(nagasa):
        xx,yy=sa[a]
        ss=sa.count([xx,yy])
        ans.append(ss)
        if len(sa)==0:
            break
    kotae=max(ans)
    print(N-kotae)

else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
ans = [0] * (N - 1)

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

for j in range(N-1):
    diff =  str( x[j+1] - x[j] ) + 'x' +  str( y[j+1] - y[j] ) + 'y'
    ans[j] = diff

print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
N = int(input())

xlist = []
ylist = []

for i in range(N):
    x, y = map(int,input().split())
    xlist.append(x)
    ylist.append(y)

xlist_ = []
ylist_ = []

for i in range(N-1):
    xlist_.append(xlist[i+1] - xlist[i])
    ylist_.append(ylist[i+1] - ylist[i])

hoge = len(dict(zip(xlist_,ylist_)))

print(int(hoge))

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]])
    q.append([a[i][0]-p[0],a[i][1]-p[1]])
  print(t)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict

n = int(input())
patterns = defaultdict(int)

last_x, last_y = map(int, input().split())
for _ in range(1, n):
    x, y = map(int, input().split())
    diff_x = x - last_x
    diff_y = y - last_y
    last_x, last_y = x, y
    pattern = "({0}:{1})".format(diff_x, diff_y)
    patterns[pattern] += 1

if n > 1:
    ans = n - max(patterns.values())
else:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import statistics
import math
from collections import Counter
N=int(input())
x=[]
y=[]
for a in range(N):
    b,c=(int(x) for x in input().split())
    x.append(b)
    y.append(c)
sa=deque([[0,0]])
if N>1:
    for a in range(N):
        for b in range(N-a-1):
            sx=abs(x[a]-x[a+b+1])
            sy=abs(y[a]-y[a+b+1])
            sa.append([sx,sy])
    sa.remove([0,0])
    ans=[]
    nagasa=len(sa)
    print(sa)
    for a in range(nagasa):
        xx,yy=sa[a]
        ss=sa.count([xx,yy])
        ans.append(ss)
        if len(sa)==0:
            break
    kotae=max(ans)
    print(N-kotae)

else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    xin, yin = map(int,input().split())
    x.append(xin)
    y.append(yin)
relative_co = [[] for i in range(N)]
pattern = []
min_cost = 50
for i in range(N):
    for j in range(N):
        tempx = x[i]-x[j]
        tempy = y[i]-y[j]
        pattern.append((tempx, tempy))
        relative_co[i].append((tempx, tempy))
patterns = len(pattern)
for i in range(patterns):
    if pattern[i] == (0,0):
        continue
    cur_cost = 0
    for j in range(N):
        if not pattern[i] in relative_co[j]:
            cur_cost += 1
    if cur_cost < min_cost:
        min_cost = cur_cost
print(str(min_cost))

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
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]
            g = gcd(x, y)
            x = int(x / g)
            y = int(y / g)
            if x == 0:
                C.append([0, 1])
            elif y == 0:
                C.append([1, 0])
            else:
                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:
                if x_t == 0:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)

            elif C[c][1] == 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:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

import collections

N = int(input())
XYs = [tuple(mi()) for _ in range(N)]

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

sa_list = []
import itertools
for (ax, ay), (bx, by) in itertools.combinations(XYs, 2):
  sa_list.append((ax-bx,ay-by) if ax-bx>=0 else (-(ax-bx),-(ay-by)))

#最も多い差の個数（これ-1を短縮できるはず）
#print(N-collections.Counter(sa_list).most_common()[0][1])

#最も多い差をタプルで受ける
mostcommon = collections.Counter(sa_list).most_common()[0][0]
#print(mostcommon)


#print(sa_list)
cnt = 0
ans = N #ここから引いていく
#aとbの差がmostcommonと一致したらvisitedに入れる
visited = [0] * N
for a in range(0, N):
  tmpsame = 0 #今見ているaと差が同じものの数
  for b in range(0, N):
    if a>=b or visited[b]!=0: continue
    sa = sa_list[cnt]
    if sa == mostcommon:
#      print('same')
      ans -= 1
      visited[b] = 1
    cnt += 1
  visited[a] = 1
#    print(sa)

if len(sa_list)>=2:
  #次に多い差をタプルで受ける
  mostcommon = collections.Counter(sa_list).most_common()[1][0]
  cnt = 0
  ans2 = N #ここから引いていく
  #aとbの差がmostcommonと一致したらvisitedに入れる
  visited2 = [0] * N
  for a in range(0, N):
    tmpsame = 0 #今見ているaと差が同じものの数
    for b in range(0, N):
      if a>=b or visited2[b]!=0: continue
      sa = sa_list[cnt]
      if sa == mostcommon:
        ans2 -= 1
        visited2[b] = 1
      cnt += 1
    visited2[a] = 1
  print(min(ans, ans2))
else:
  print(ans)

Submission status: Wrong Answer

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

positions.sort()

ans = float('inf')

for start in range(N-1):
    sx, sy = positions[start]
    for target in range(start+1, N):
        tx, ty = positions[target]
        p = tx - sx
        q = ty - sy
        cost = target
        if cost < ans:
            next_pos = target + 2
            for current in range(target+1, N-1):
                cx, cy = positions[current]
                while next_pos < N:
                    nx, ny = positions[next_pos]
                    if cx + p < nx:
                        cost += 1
                        break
                    if cx + p == nx:
                        if cy + q == ny:
                            next_pos += 1
                            break
                        elif cy + q < ny:
                            cost += 1
                            break
                    next_pos += 1
                if next_pos == N:
                    cost += 1
        ans = min(ans, cost)
print(ans)

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] >= N :
        print(1)
    else:
        print(N - cma_sorted[-1][1])
else:
    print(N)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 6)


def main():
    N = int(input())
    balls = [list(map(int, input().split())) for _ in range(N)]
    diffs = []
    for i in range(N):
        for j in range(i + 1, N):
            diffs.append([balls[i][0] - balls[j][0],
                          balls[i][1] - balls[j][1]])
    max_balls_on_line = 1
    for k, d in enumerate(diffs):
        count = 0
        for l, e in enumerate(diffs):
            if (d[0] == e[0] and d[1] == e[1]) or (d[0] == -e[0] and d[1] == -e[1]):
                count += 1
        if count > max_balls_on_line:
            max_balls_on_line = count

    print(N - max_balls_on_line)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

cnt = 1
mae = [21412423, 234614341]
while len(List)>0:
    length = len(List)
    num = [0]*length
    for i in range(length):
        for j in range(length):
            if (List[i][0]!=List[j][0])&(List[i][1]!=List[j][1]):
                num[i]+=1
    
    idx = num.index(min(num))
    if (List[idx][0]==mae[0])|(List[idx][1]==mae[1]):
        cnt+=1
    mae = List[idx]
    List.remove(mae)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys


N = int(input())
p = []
dic = {}
sameX = {}
allNum = []

for i in range(N):

    x,y = map(int,input().split())

    p.append([x,y])

    allNum.append(i)


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

for i in range(N):

    for j in range(i):

        ji = [j,i]
        

        if p[j][0] - p[i][0] != 0:

            a = ( p[j][1] - p[i][1] ) / ( p[j][0] - p[i][0] )
            b = p[j][1] - ( a * p[j][1] )

            if a == -0.0:
                a = 0.0
            
            ab = [a,b]

            if ( str (ab) )  in dic:
                dic[ str (ab) ].append(ji)

            else:
                dic[ str(ab) ] = [ji]

        elif p[j][0] - p[i][0] == 0:

            if p[j][0] in sameX:
                sameX[ p[j][0] ].append(ji)
            else:
                sameX[ p[j][0] ] = [ji]
            

#print  (dic,sameX)
        

DorS = 0
maxi = 0
keys = ""
ans = 0

while len(allNum) > 0:

    DorS = 0
    maxi = 0
    keys = ""

    for i in dic:
        
        eable = {}
        
        for j in dic[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            
                

        if len(eable) >= maxi:

            
            DorS = 0
            maxi = len(dic[i])
            keys = i

    for i in sameX:

        eable = {}

        for j in sameX[i]:

            if j[0] in allNum:
                eable[j[0]] = 1
            if j[1] in allNum:
                eable[j[1]] = 1            

        if len(eable) >= maxi:

            DorS = 1
            maxi = len(sameX[i])
            keys = i


    if DorS == 0:

        delPs = dic[keys]
        del dic[keys]

    else:

        delPs = sameX[keys]
        del sameX[keys]


    #print (delPs)

    rmFlag = False

    for i in delPs:

        if i[0] in allNum :
            allNum.remove(i[0])
            rmFlag = True

        if i[1] in allNum :
            allNum.remove(i[1])
            rmFlag = True

    if rmFlag :
        ans += 1

    #print (allNum)


print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    xin, yin = map(int,input().split())
    x.append(xin)
    y.append(yin)
relative_co = [[] for i in range(N)]
pattern = []
min_cost = 50
for i in range(N):
    for j in range(N):
        tempx = x[i]-x[j]
        tempy = y[i]-y[j]
        pattern.append((tempx, tempy))
        relative_co[i].append((tempx, tempy))
patterns = len(pattern)
for i in range(patterns):
    if pattern[i] == (0,0):
        continue
    cur_cost = 0
    for j in range(N):
        if not pattern[i] in relative_co[j]:
            cur_cost += 1
    if cur_cost < min_cost:
        min_cost = cur_cost

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)

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)
if N-1 < max(ans):
    reduce = N-1
else:
    reduce = max(ans)

print(N - reduce)

Submission status: Wrong Answer

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

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

x_y.sort(key=lambda x: x[0])
x_y_gap = [[x_y[i+1][0]-x_y[i][0], x_y[i+1][1]-x_y[i][1]] for i in range(N-1)]

x_y_count = 0
combination = [10**10, 10**10]
for i in x_y_gap:
  if x_y_gap.count(i) >= x_y_count:
    combination = i 
    x_y_count = x_y_gap.count(i)

answer = 1
dp = [0]*(N-1)
dp[0] = 1
for i in range(1, N-1):
  x = x_y[i][0] - combination[0]
  y = x_y[i][1] - combination[1]
  if [x,y] in x_y:
    dp[i] = 0
  else:
    dp[i] = 1


print(sum(dp))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
l2 = []

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

for i in range(len(l)):
    for j in range(i+1, len(l)):
        dif1 = l[i][0] - l[j][0]
        dif2 = l[i][1] - l[j][1]
        if dif1 != 0 and dif2 != 0:
            l2.append(str(dif1) + ' ' + str(dif2))

try:
    cnt = l2.count(max(l2, key=l2.count))
except:
    cnt = 0
    
print(n - cnt)

Submission status: Wrong Answer

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

    min_cost = float('inf')
    for i in range(n):
        x,y = coords[i][0],coords[i][1]
        for j in range(n):
            if i == j:
                continue
            visited = set()
            visited.add((x,y))
            moves = 1
            x1,y1 = coords[j][0],coords[j][1]
            p,q = x1-x,y1-y
            visited.add((x1,y1))
            while len(visited) != n:
                if ((x1+p,y1+q) in coords) and ((x1+p,y1+q) not in visited):
                    visited.add((x1+p,y1+q))
                    x1 += p
                    y1 += q
                else:
                    moves += 1
                    for k in range(n):
                        if (coords[k][0],coords[k][1]) not in visited:
                            x1,y1 = coords[k][0],coords[k][1]
                            visited.add((x1,y1))
                            break
                        
            min_cost = min(min_cost,moves)

    if n == 1:
        min_cost = 1
    print(min_cost)
            

main()

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
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]
            g = gcd(x, y)
            x = int(x / g)
            y = int(y / g)
            if x == 0:
                C.append([0, 1])
            elif y == 0:
                C.append([1, 0])
            else:
                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]]]
    print(C[c])
    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:
                if x_t == 0:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)

            elif C[c][1] == 0:
                if y_t == 0:
                    break
                elif j == l - 1:
                    tmp.append(arr_i)
            else:
                print(x_t, y_t)
                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(S)
print(min(S))

Submission status: Wrong Answer

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 (-p, -q,) in pqlist:
      tuple_pq = (-p, -q)
    if not (tuple_pq in pqlist):
      pqlist.append(tuple_pq)
      pqcount[tuple_pq] = 1
    else:
      pqcount[tuple_pq] += 1

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

Submission status: Wrong Answer

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

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
sa = []
for i in range(n):
    for j in range(n):
        if i != j:
            sa.append([xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]])

ans = 10 ** 15
for p, q in sa:
    tmp = 1
    for i in range(1, n):
        a = xy[i][0] - xy[i - 1][0]
        b = xy[i][1] - xy[i - 1][1]
        if p != a or q != b:
            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):
        a = xy[i][0] - xy[i - 1][0]
        b = xy[i][1] - xy[i - 1][1]
        if p != a or q != b:
            tmp += 1
    ans = min(ans, tmp)

if n == 1:
    ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
cost = float('Inf')
if N == 1:
    print(1)
    exit()
for st in xy:
    for nx in xy:
        if st != nx:
            p = nx[0] - st[0]
            q = nx[1] - st[1]
        else:
            continue
        que = deque()
        que.append(st)
        for t in xy:
            if t != st:
                que.append(t)
        tmp = 0
        flag = True
        while len(que) > 0:
            if flag:
                tmp += 1
            st2 = que.popleft()
            flag = True
            nque = deque()
            for nx2 in que:
                if (nx2[0] - st2[0]) == p and (nx2[1] - st2[1]) == q:
                    nque.appendleft(nx2)
                    flag = False
                else:
                    nque.append(nx2)
            que = nque
        if tmp < cost:
            cost = tmp
print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [[int(x) for x in input().split()] for i in range(N)]
xy = sorted(xy)
ans = 1
if N <= 2:
  print(ans)
else:
  list_xypq = [[xy[0][0],xy[0][1],xy[1][0]-xy[0][0],xy[1][1]-xy[0][1]]]
  for i in range(2,N):
    x = int(xy[i][0])
    y = int(xy[i][1])
    for j in range(len(list_xypq)):
      x_tmp = int(list_xypq[j][0])
      y_tmp = int(list_xypq[j][1])
      p_tmp = int(list_xypq[j][2])
      q_tmp = int(list_xypq[j][3])
      if p_tmp == 10e10 and q_tmp == 10e10:
        list_xypq[j][2] = x-x_tmp
        list_xypq[j][3] = y-y_tmp
        break
      if p_tmp == 0 and q_tmp != 0:
        if x-x_tmp == 0 and (y-y_tmp)%q_tmp == 0:
          break
      elif p_tmp != 0 and q_tmp == 0:
        if (x-x_tmp)%p_tmp == 0 and y-y_tmp == 0:
          break
      elif p_tmp == 0 and q_tmp == 0:
        if x-x_tmp == 0 and y-y_tmp == 0:
          break
      else:
        if (x-x_tmp)%p_tmp == 0 and (y-y_tmp)%q_tmp == 0 and (x-x_tmp)//p_tmp == (y-y_tmp)//q_tmp:
          break
    else:
      list_xypq.append([x,y,10e10,10e10])
      ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

xlist = []
ylist = []

for i in range(N):
    x, y = map(int,input().split())
    xlist.append(x)
    ylist.append(y)

# print(xlist)
# print(ylist)

xlist_ = []
ylist_ = []

for i in range(N-1):
    xlist_.append(xlist[i+1] - xlist[i])
    ylist_.append(ylist[i+1] - ylist[i])

# print(xlist_)
# print(ylist_)

print(len(dict(zip(xlist_,ylist_))))

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-1):
        if([point[k][0]+p,point[k][1]+q] in point):
            merge+=1
    ans=max(ans,merge)
print(N-ans)