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())
l = []
for i in range (n):
    a = list(map(int, input().split()))
    l.append(a)

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

ans = 0
for i in range(n-1):
    count = 0
    x = l[i+1][0] - l[i][0]
    y = l[i+1][1] - l[i][1]
    z = [l[i][0] + x, l[i][1] + y]
    while(True):
        if z in l:
            count += 1
            z[0] += x
            z[1] += y
        else:
            break

    if count > ans:
        ans = count

print(n - ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list()
for _ in range(n):
    a.append(list(map(int, input().split())))
if n in [1,2]:
    print(1)
else:
    diff = list()
    for i in range(len(a) - 1):
        for j in range(i+1, len(a)):
            x = a[j][0]-a[i][0]
            y = a[j][1]-a[i][1]
            if x<0 and y<0:
                z = (-x,-y)
            elif x<0 and y>0:
                z = (-x,-y)
            else:
                z = (x,y)
            diff.append(z)
    t_diff = Counter(diff).most_common(1)[0][1]
    print(n-t_diff)

Submission status: Wrong Answer

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

ans = float('inf')
for i in range(N):
    for j in range(N):
        xi, yi = P[i]
        xj, yj = P[j]

        if xi == xj:
            hit = 0
            for k in range(N):
                for l in range(N):
                    xk, yk = P[k]
                    xl, yl = P[l]
                    if xk == xl:
                        hit += 1
        else:
            steep = (yj - yi) / (xj - xi)
            hit = 0
            for k in range(N):
                for l in range(N):
                    xk, yk = P[k]
                    xl, yl = P[l]

                    if xk == xl:
                        continue
                    else:
                        if steep == (yl - yk) / (xl - xk):
                            hit += 1
            ans = min(ans, N - hit // 2)

print(max(1, ans))

Submission status: Wrong Answer

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

if N == 1:
    print(1)
    
else:
    B = sorted(L, key=lambda x: x[1], reverse=True)  
    B = sorted(B, key=lambda x: x[0])
    
    dic_x = {}
    dic_y = {}
    for i in range(N-1):
        if B[i+1][0] - B[i][0] in dic_x:
            dic_x[B[i+1][0] - B[i][0]] += 1

        else:
            dic_x[B[i+1][0] - B[i][0]] = 1


        if B[i+1][1] - B[i][1] in dic_y:
            dic_y[B[i+1][1] - B[i][1]] += 1

        else:
            dic_y[B[i+1][1] - B[i][1]] = 1


    tmp_x = max(dic_x.items(), key=lambda x:x[1])[0]
    tmp_y = max(dic_y.items(), key=lambda x:x[1])[0]
    
    if tmp_x == 0 and tmp_y == 0:
        tmp_x.pop(0)
        tmp_x = max(dic_x.items(), key=lambda x:x[1])[0]
        ans_1_1 = 0
        for i in range(N-1):
            if B[i][0] + tmp_x == B[i+1][0] and B[i][1] + tmp_y == B[i+1][1]:
                pass
            else:
                ans_1_1 += 1
                
        tmp_y.pop(0)
        tmp_y = max(dic_y.items(), key=lambda x:x[1])[0]
        ans_1_2 = 0
        for i in range(N-1):
            if B[i][0] + tmp_x == B[i+1][0] and B[i][1] + tmp_y == B[i+1][1]:
                pass
            else:
                ans_1_2 += 1
                
        ans_1 = min(ans_1_1, ans_1_2)
                
                
    else:
        ans_1 = 0
        for i in range(N-1):
            if B[i][0] + tmp_x == B[i+1][0] and B[i][1] + tmp_y == B[i+1][1]:
                pass
            else:
                ans_1 += 1

    B = sorted(L, key=lambda x: x[0], reverse=True)      
    B = sorted(B, key=lambda x: x[1])

    dic_x = {}
    dic_y = {}
    for i in range(N-1):
        if B[i+1][0] - B[i][0] in dic_x:
            dic_x[B[i+1][0] - B[i][0]] += 1

        else:
            dic_x[B[i+1][0] - B[i][0]] = 1


        if B[i+1][1] - B[i][1] in dic_y:
            dic_y[B[i+1][1] - B[i][1]] += 1

        else:
            dic_y[B[i+1][1] - B[i][1]] = 1


    tmp_x = max(dic_x.items(), key=lambda x:x[1])[0]
    tmp_y = max(dic_y.items(), key=lambda x:x[1])[0]
    
    
    
    if tmp_x == 0 and tmp_y == 0:
        tmp_x.pop(0)
        tmp_x = max(dic_x.items(), key=lambda x:x[1])[0]
        ans_1_1 = 0
        for i in range(N-1):
            if B[i][0] + tmp_x == B[i+1][0] and B[i][1] + tmp_y == B[i+1][1]:
                pass
            else:
                ans_1_1 += 1
                
        tmp_y.pop(0)
        tmp_y = max(dic_y.items(), key=lambda x:x[1])[0]
        ans_1_2 = 0
        for i in range(N-1):
            if B[i][0] + tmp_x == B[i+1][0] and B[i][1] + tmp_y == B[i+1][1]:
                pass
            else:
                ans_1_2 += 1
                
        ans_2 = min(ans_1_1, ans_1_2)
        
    else:
        ans_2 = 0
        for i in range(N-1):
            if B[i][0] + tmp_x == B[i+1][0] and B[i][1] + tmp_y == B[i+1][1]:
                pass
            else:
                ans_2 += 1

    print(min(ans_1, ans_2)+1)

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

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

Submission status: Wrong Answer

Solution code:

from collections import defaultdict

def read_input():
    n = int(input())

    points = []
    for i in range(n):
        points.append(tuple(map(int, input().split())))

    return n, points


# calc p3 is on line made by p1 and p2
def check_on_line(p1, p2, p3):
    a = (p2[0] - p1[0], p2[1] - p1[1])
    b = (p3[0] - p1[0], p3[1] - p1[1])

    axb = a[0]*b[1] - a[1]*b[0]

    # on line
    if axb == 0:
        return True
    return False


def dist_point_to_point(p1, p2):
    return (p2[0] - p1[0], p2[1] - p1[1])


def submit():
    n, points = read_input()

    p2p_dist = {}
    pd_list = defaultdict(list)
    for p1 in points:
        for p2 in points:
            if p1 == p2:
                continue
            p2p_dist[(p1, p2)] = dist_point_to_point(p1, p2)

            for p3 in points:
                if check_on_line(p1, p2, p3):
                    pd_list[(p1, p2p_dist[(p1, p2)])].append(p3)

    pq_list = list(set(p2p_dist.values()))

    min_line_c = 51
    for p, q in pq_list:
        line_c = 0
        point_c = 0
        used = {}
        for s in points:
            used[s] = False

        # print(p, q)
        for s in points:
            if used[s]:
                continue
            lines = pd_list[(s, (p, q))]

            if lines:
                for pl in lines:
                    used[pl] = True
                    point_c += 1
            else:
                used[s] = True
                point_c += 1

            line_c += 1
            # print(used, line_c)

            if point_c == n:
                break

        if min_line_c > line_c:
            min_line_c = line_c

    print(min_line_c)

if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 1:
    print(1)
    exit()
D = []
for i in range(N):
    x, y = map(int, input().split())
    D.append((i, x, y))
D = sorted(D)

d = set()
for i in range(N):
    for j in range(N):
        d.add((D[i][0] - D[j][0], D[i][1] - D[j][1]))


d = list(d)
num = float('inf')
for p, q in d:
    if p == 0 and q == 0:
        continue
    used = [0] * N
    prex, prey = D[0][0], D[0][1]
    used[0] = 1
    tmp = 1
    for k in range(N - 1):
        for i in range(N):
            if used[i]:
                continue
            if D[i][0] - prex == p and D[i][1] - prey == q:
                prex = D[i][0]
                prey = D[i][1]
                used[i] = 1
                break
        else:
            tmp += 1
            for i in range(N):
                if not used[i]:
                    prex = D[i][0]
                    prey = D[i][1]
                    used[i] = 1
                    break
    num = min(tmp, num)

print(num)

Submission status: Wrong Answer

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

sort_x = sorted(xy)
sort_y = sorted(xy, key=lambda x:x[1])
diff = []
prev_x = 0
prev_y = 0
for (x,y) in sort_x:
    diff.append((x-prev_x, y-prev_y))
    prev_x = x
    prev_y = y

diff.pop(0)
x_max = len(set(diff))

diff = []
prev_x = 0
prev_y = 0
for (x,y) in sort_y:
    diff.append((x-prev_x, y-prev_y))
    prev_x = x
    prev_y = y

diff.pop(0)
y_max = len(set(diff))

print(min(x_max, y_max))

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
cst = 1
xy.sort(key = lambda x:x[0])
keep = xy[0]
if N != 1:
    p = xy[1][0]-xy[0][0]
    q = xy[1][1]-xy[0][1]
    for i in range(1,N-1):
        if not(xy[i][0] == keep[0]+p and xy[i][1] == keep[1]+q):
            cst += 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 += 1
else:
    print(1)

print(cst)

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 1:
    print(0)
else:
    xys = [[int(j) for j in input().split()] for i in range(N)]
    xys.sort(key=lambda x: x[0])
    hikizan = [[xy2[0] - xy1[0], xy2[1] - xy1[1]] for i, xy1 in enumerate(xys) for j, xy2 in enumerate(xys) if i < j]
    counting = [sum([1 for c in hikizan if h[0]==c[0] and h[1]==c[1]]) for h in hikizan]
    print(N - max(counting))

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)]
    a = sorted(a, key=lambda x:(x[0],x[1]))

    x.sort()
    y.sort()

    sx = [x[i+1]-x[i] for i in range(N-1)]
    sy = [y[i+1]-y[i] for i in range(N-1)]

    from collections import Counter

    csx = Counter(sx)
    csy = Counter(sy)

    # p = csx.most_common()[0][0]
    p = [i for i,v in csx.most_common()]
    pm = [-1*i for i in p]
    # print(p)
    # q = csy.most_common()[0][0]
    q = [i for i,v in csy.most_common()]
    qm = [-1*i for i in q]
    p = p + pm
    q = q + qm
    p.sort()
    q.sort()
    p = set(p)
    q = set(q)
    # print(p)

    ans = 10000000000
    for i in p:
        for j in q:
            tans = 1
            for k in range(1,N):
                s,t = a[k]
                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())
List = [list(map(int,input().split())) for i in range(N)]

import copy

List.sort(key=lambda x:x[0])

result = float('inf')

for i in range(N):
    for j in range(N-i-1):
        p = List[i+j+1][0] - List[i][0]
        q = List[i+j+1][1] - List[i][1]
        tmp_list = copy.deepcopy(List)
        cost = 0
        print(p,q)
        
        for k in range(N):
            print(tmp_list)
            if [tmp_list[0][0] + p, tmp_list[0][1] + q] in List:
                tmp_cost = 0
            else:
                tmp_cost = 1
            cost += tmp_cost
            del tmp_list[0]
        print(cost)    
        if result > cost:
            result = cost
                    
print(result)

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]


    ans = num
    for i in range(num):
        for j in range(num):
            if i == j:
                continue

            now_kyori = [data[i][0] - data[j][0], data[i][1] - data[j][1]]
            visit_list = [0 for i in range(num)]
            visit_list[i], visit_list[j] = 1, 1

            kari_num = 1

            for k in range(num):
                if visit_list[k]:
                    continue

                now_data = data[k]

                flg = 1
                for l in range(num):
                    if visit_list[l]:
                        a = data[l][0] - now_data[0]
                        b = data[l][1] - now_data[1]

                        if now_kyori[0] == 0 and now_kyori[1] == 0:
                            if a == now_kyori[0] and b == now_kyori[0]:
                                flg = 0
                        elif now_kyori[0] == 0:
                            if a == now_kyori[0] and b % now_kyori[1] == 0:
                                if b + now_kyori[1] == 0 or b - now_kyori[1] == 0:
                                    flg = 0
                        elif now_kyori[1] == 0:
                            if b == now_kyori[1] and a % now_kyori[0] == 0:
                                if a + now_kyori[0] == 0 or a - now_kyori[0] == 0:
                                    flg = 0
                        else:
                            if a % now_kyori[0] == 0 and b % now_kyori[1] == 0:
                                if a // now_kyori[0] == b // now_kyori[1]:
                                    if a + now_kyori[0] == 0 or a - now_kyori[0] == 0:
                                        flg = 0
                        if flg == 0:
                            break

                if flg:
                    kari_num += 1
                visit_list[k] = 1


            ans = min(kari_num, ans)

    print(ans)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

n = int(input())
X, Y = zip(*[[int(i) for i in input().split()] for j in range(n)])

used = [False] * n
D = {(X[i], Y[i]): i for i in range(n)}

def dfs(i, p, q):
    if used[i]:
        return
    used[i] = True
    if (X[i] + p, Y[i] + q) in D:
        dfs(D[X[i] + p, Y[i] + q], p, q)
    if (X[i] - p, Y[i] - q) in D:
        dfs(D[X[i] - p, Y[i] - q], p, q)

ans = int(1e12)

for i in range(n):
    for j in range(i + 1, n):
        p = X[i] - X[j]
        q = Y[i] - Y[j]
        used = [False] * n
        cnt = 0
        for k in range(n):
            if used[k]:
                continue
            cnt += 1
            dfs(k, p, q)

        ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
coords = []
dist = {}
same = {}
for i in range(n):
    a, b = (int(_) for _ in input().split())
    if [a, b] not in coords:
        for coord in coords:
            x = abs(coord[0] - a)
            y = abs(coord[1] - b)
            if (x,y) != (0, 0):
                if (x,y) not in dist:
                    dist[(x,y)] = 1
                else:
                    dist[(x,y)] = dist[(x,y)] + 1
        coords.append([a,b])
        same[(a, b)] = 1
    else:
        same[(a, b)] = same[(a, b)] + 1
if n == 1 or n == 2:
    print(1)
else:
    ans = 0
    for distance in dist:
        if dist[distance] > ans:
            ans = dist[distance]
            #print(distance)
    for s in same:
        if same[s] > ans:
            ans = same[s]
    if ans == n:
        print(1)
    else:
        print(n - ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
xy = [tuple([int(i) for i in input().split()]) for i in range(n)]
li = []
for i in range(n):
    for j in range(n):
        if j == i:  continue
        li.append((abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))

cnt,p,q = 0,0,0
for k,v in Counter(li).items():
    if cnt < v:
        cnt = v
        p,q = k

ans = 1
for i in range(1,n):
    if (xy[i][0]-p,xy[i][1]-q) != (xy[i-1][0],xy[i-1][1]):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]
XY.sort(key = lambda x: (-x[0], -x[1]))
diff = []
for X, Y in XY:
  for X2, Y2 in XY[1:]:
    if (X2 - X, Y2 - Y) == (0, 0):
      continue
    diff.append((X2-X, Y2-Y))

memo = False
ans = 1e9+7
for x, y in diff:
  cost = 1
  for X, Y in XY:
    if not memo:
      memo = (X, Y)
      continue
    if (X - x, Y - y) == memo:
      pass
    else:
      cost += 1
    memo = (X, Y)
  ans = min(cost, ans)
  memo = False
print(ans)

Submission status: Wrong Answer

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

xy.sort(key=lambda x:(x[0],x[1]))
d1 = []
for i in range(1, N):
    x = xy[i-1][0] - xy[i][0]
    y = xy[i-1][1] - xy[i][1]
    d1.append((x, y))
P1 = 0
for D in d1:
    P1 = max(d1.count(D), P1)

xy.sort(key=lambda x:(x[0],x[1]), reverse=True)
d2 = []
for i in range(1, N):
    x = xy[i-1][0] - xy[i][0]
    y = xy[i-1][1] - xy[i][1]
    d2.append((x, y))
P2 = 0
for D in d2:
    P2 = max(d2.count(D), P2)


xy.sort(key=lambda x:(x[1],x[0]))
d3 = []
for i in range(1, N):
    x = xy[i-1][0] - xy[i][0]
    y = xy[i-1][1] - xy[i][1]
    d3.append((x, y))
P3 = 0
for D in d3:
    P3 = max(d3.count(D), P3)

xy.sort(key=lambda x:(x[1],x[0]), reverse=True)
d4 = []
for i in range(1, N):
    x = xy[i-1][0] - xy[i][0]
    y = xy[i-1][1] - xy[i][1]
    d4.append((x, y))
P4 = 0
for D in d4:
    P4 = max(d4.count(D), P4)


cut_P = max(P1, P2, P3, P4)
ans = N - cut_P
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

if N == 1:
    print(1)

coor = []
for i in range(N):
    (x,y) = (int(i) for i in input().split())
    coor.append((x,y))
    
diffs = []
for i in range(N-1):
    for j in range(i+1, N):
        diffs.append((coor[j][0]-coor[i][0], coor[j][1]-coor[i][1]))
    
m = 1

for i in range(N-1):
    times = 1
    for j in range(N-1):
        if diffs[i] == diffs[j]:
            times += 1
    if times > m:
        m = times

ans = N - m   

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
answer = []
answer2 = []
lis = []
lis2 = []
for i in range(N):
    x, y = map(int, input().split())
    lis.append([x, y])
    lis2.append([y,x])
sort_lis = sorted(lis)

sort_lis2 = sorted(lis2)


if N == 1:
    print(1)
    exit()
for i in range(N-1):
    answer.append([sort_lis[i][0] -sort_lis[i+1][0],sort_lis[i][1]-sort_lis[i+1][1]])
    answer2.append([sort_lis2[i][0] -sort_lis2[i+1][0],sort_lis2[i][1]-sort_lis2[i+1][1]])
ans = list(map(tuple,answer))
#print(ans)
ans2 = list(map(tuple,answer2))
#print(ans2)
a = Counter(ans).most_common()
a2 = Counter(ans2).most_common()
if a[0][1] > a2[0][1]:
    c = 1
    for i in range(1,len(a)):
        c += a[i][1]
else:
   c = 1
   for i in range(1,len(a2)):
       c += a2[i][1]
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def get_2dline(p1, p2):
    return p2[0] - p1[0], p1[1] - p2[1]


def main():
    n = int(input())
    points = []
    for _ in range(n):
        points.append(tuple(map(int, input().split())))

    lines = set()
    for i in range(n):
        for j in range(n):
            a, b = get_2dline(points[i], points[j])
            lines.add((a, b))
            lines.add((b, a))
            lines.add((-a, b))
            lines.add((-b, a))
    lines.discard((0, 0))

    res = n
    for p, q in lines:
        counter = set()
        for x, y in points:
            counter.add(q * x + p * y)
        res = min(res, len(counter))
    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter as c
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda xy: xy[0])
if N == 1:
    print(1)
    exit()

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

p, q = sorted(list(c(inclination).items()),
              key=lambda x: (x[1], -x[0][0]))[-1][0]

cnt = 1
for i in range(1, N):
    x_pre = XY[i-1][0]
    y_pre = XY[i-1][1]
    x = XY[i][0]
    y = XY[i][1]
    if not (x - x_pre == p and y - y_pre == q):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
balls=[]
distance=[]
if n==1:
  print(1)
else:
  for i in range(n):
    balls.append(list(map(int,input().split())))
  for i in range(n-1):
    for j in range(i+1,n):
      distance.append(str(balls[i][0]-balls[j][0])+" "+str(balls[i][1]-balls[j][1]))
  d=Counter(distance)
  print(n-d.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
x = [0]*n
y = [0]*n
p_q = []
for i in range(n):
    x[i], y[i] = map(int, input().split())
cnt = 1
for i in range(1, n):
    p_q.append([x[i]-x[i-1], y[i]-y[i-1]])
p_q.sort()
new = []
for i in range(1, len(p_q)):
    new.append(list(set(p_q[i])-set(p_q[i-1])))
for i in range(len(new)):
    if new[i] != []:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return tuple(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XY):
    c = defaultdict(list)
    for i in range(N):
        x, y = XY[i]
        for j in range(i+1, N):
            a, b = XY[j]
            c[(x-a, y-b)].append((i, j))

    ans = 0
    for k, v in c.items():
        tmp = set()
        for x, y in v:
            tmp.add(x)
            tmp.add(y)
        ans = max(ans, len(tmp))
    return N - ans + 1


def main():
    N = read_int()
    XY = [read_int_n() for _ in range(N)]
    print(slv(N, XY))

    # N = 50
    # XY = [(random.randint(1, 10), random.randint(1, 10)) for _ in range(N)]
    # print(slv(N, XY))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def get_2dline(p1, p2):
    return p2[0] - p1[0], p1[1] - p2[1]


def main():
    n = int(input())
    points = []
    for _ in range(n):
        points.append(tuple(map(int, input().split())))

    lines = set()
    for i in range(n):
        for j in range(n):
            a, b = get_2dline(points[i], points[j])
            lines.add((a, b))
            lines.add((b, a))
            lines.add((-a, b))
            lines.add((-b, a))
    lines.discard((0, 0))

    res = n
    for p, q in lines:
        counter = set()
        for x, y in points:
            counter.add(p * x + q * y)
        res = min(res, len(counter))
    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
str = input()
N = int(str.split()[0])

x = []
y = []
t = []
for i in range(N) :
	str = input()
	sStr = str.split()
	x.append(int(sStr[0]))
	y.append(int(sStr[1]))
	t.append(i)
for i in range(N) :
	for j in range(i, N) :
		if (x[i] < x[j]) :
			x[i], x[j] = x[j], x[i]
			y[i], y[j] = y[j], y[i]
			t[i], t[j] = t[j], t[i]

for i in range(N) :
	for j in range(i, N) :
		if (x[i] == x[j]) :
			if (y[i] < y[j]) :
				x[i], x[j] = x[j], x[i]
				y[i], y[j] = y[j], y[i]
				t[i], t[j] = t[j], t[i]

a = []

for i in range(N - 1) :
	tuple = (x[i] - x[i+1], y[i] - y[i+1])
	a.append(tuple)

ab = 0
for tu in a :
	co = 1
	to = 1
	for i in range(N - 1) :
		tuple = (x[i] - x[i+1], y[i] - y[i+1])
		if (tuple != tu) :
			co = co + 1
	if (ab == 0) :
		ab = co
	if (ab > co) :
		ab = co

a = []

for i in range(N) :
	for j in range(i, N) :
		if (y[i] == y[j]) :
			if (x[i] < x[j]) :
				x[i], x[j] = x[j], x[i]
				y[i], y[j] = y[j], y[i]
				t[i], t[j] = t[j], t[i]

for i in range(N - 1) :
	tuple = (x[i] - x[i+1], y[i] - y[i+1])
	a.append(tuple)

for tu in a :
	co = 1
	to = 1
	for i in range(N - 1) :
		tuple = (x[i] - x[i+1], y[i] - y[i+1])
		if (tuple != tu) :
			co = co + 1
		ab = co
	if (ab > co) :
		ab = co
		
print(ab)