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

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using VirtualContest20200530.Questions;
using VirtualContest20200530.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace VirtualContest20200530.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();

            if (n == 1)
            {
                yield return 1;
                yield break;
            }

            var points = new Point[n];

            for (int i = 0; i < n; i++)
            {
                var xy = inputStream.ReadIntArray();
                points[i] = new Point(xy[0], xy[1]);
            }

            Array.Sort(points);

            var diffs = new HashSet<Diff>();
            for (int i = 0; i < points.Length; i++)
            {
                for (int j = i + 1; j < points.Length; j++)
                {
                    diffs.Add(points[i].GetDiff(points[j]));
                }
            }

            yield return diffs.Min(diff => GetCost(diff, points));
        }

        int GetCost(Diff diff, Point[] points)
        {
            var seen = new bool[points.Length];
            var current = points[0];
            seen[0] = true;
            var cost = 1;

            while (seen.Any(b => !b))
            {
                var next = FindNext(diff, current, points, seen);
                if (next != -1)
                {
                    current = points[next];
                    seen[next] = true;
                }
                else
                {
                    cost++;
                    for (int i = 0; i < seen.Length; i++)
                    {
                        if (!seen[i])
                        {
                            current = points[i];
                            seen[i] = true;
                            break;
                        }
                    }
                }
            }

            return cost;
        }

        int FindNext(Diff diff, Point current, Point[] points, bool[] seen)
        {
            var next = new Point(current.X + diff.DX, current.Y + diff.DY);
            for (int i = 0; i < points.Length; i++)
            {
                if (!seen[i] && points[i] == next)
                {
                    return i;
                }
            }
            return -1;
        }

        public struct Point : IComparable<Point>, IEquatable<Point>
        {
            public int X { get; }
            public int Y { get; }

            public Point(int x, int y)
            {
                X = x;
                Y = y;
            }

            public Diff GetDiff(Point other) => new Diff(X - other.X, Y - other.Y);

            public int CompareTo(Point other)
            {
                var comp = X.CompareTo(other.X);
                if (comp != 0)
                {
                    return comp;
                }
                return Y.CompareTo(other.Y);
            }

            public override bool Equals(object obj)
            {
                return obj is Point && Equals((Point)obj);
            }

            public bool Equals(Point other)
            {
                return X == other.X &&
                       Y == other.Y;
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    int hashCode = 1861411795;
                    hashCode = hashCode * -1521134295 + X.GetHashCode();
                    hashCode = hashCode * -1521134295 + Y.GetHashCode();
                    return hashCode;
                }
            }

            public static bool operator ==(Point left, Point right)
            {
                return left.Equals(right);
            }

            public static bool operator !=(Point left, Point right)
            {
                return !(left == right);
            }
        }

        public struct Diff : IEquatable<Diff>
        {
            public int DX { get; }
            public int DY { get; }

            public Diff(int dx, int dy)
            {
                if (dx < 0)
                {
                    dx = -dx;
                    dy = -dy;
                }
                else if (dx == 0 && dy < 0)
                {
                    dy = -dy;
                }

                DX = dx;
                DY = dy;
            }

            public override bool Equals(object obj)
            {
                return obj is Diff && Equals((Diff)obj);
            }

            public bool Equals(Diff other)
            {
                return DX == other.DX &&
                       DY == other.DY;
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    int hashCode = 1633967671;
                    hashCode = hashCode * -1521134295 + DX.GetHashCode();
                    hashCode = hashCode * -1521134295 + DY.GetHashCode();
                    return hashCode;
                }
            }

            public static bool operator ==(Diff left, Diff right)
            {
                return left.Equals(right);
            }

            public static bool operator !=(Diff left, Diff right)
            {
                return !(left == right);
            }
        }
    }
}


namespace VirtualContest20200530
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace VirtualContest20200530.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace VirtualContest20200530.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion