All problems

Problem 696

Max Points on a Line

Hard · 30 pts · Geometry, Hash Table, Math

Problem

Given N distinct points with integer coordinates, find the largest number of them that lie on one straight line. For each point, group every other point by the direction to it; points with the same direction are on one line through the first point. Store a direction as the pair (dy, dx) divided by their greatest common divisor, with the sign normalised (for example dx > 0, or dx = 0 and dy = 1), so that no floating-point slopes are needed.

Input

The first line contains N. Each of the next N lines contains the coordinates x and y of a point.

Output

Print the maximum number of points on one line.

Constraints

1 <= N <= 300; -10^4 <= x, y <= 10^4; all points are distinct

Example input

3
1 1
2 2
3 3

Example output

3

Explanation

The points (1,1), (2,2) and (3,3) all lie on the line y = x, so the answer is 3. Any two points always lie on a common line, so the answer is at least 2 whenever N >= 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Longest Increasing Path in a Matrix Next: Count Subarrays With Fixed Bounds