eolymp
bolt
Try our new interface for solving problems

Grid

There is an innite grid on the plane consisting of vertical and horizontal lines. The lines are given by equations \{\textbf{X} = \textbf{i}·\textbf{K}\} and \{\textbf{Y} = \textbf{j}·\textbf{K}\} for any integers \textbf{i} and \textbf{j}. Also, a set of \textbf{N} points is given. We say that a point lies on the grid if it lies on at least one of the lines which form the grid. The grid may be moved parallel to the coordinate axes. Translation of the grid by vector (\textbf{dx}, \textbf{dy}) means that each line \{\textbf{X} = \textbf{i}·\textbf{K}\} is replaced by line \{\textbf{X} = \textbf{i}·\textbf{K} + \textbf{dy}\}, and each line \{\textbf{Y} = \textbf{j}·\textbf{K}\} is replaced by line \{\textbf{Y} = \textbf{j·K + dx}\}. Find the maximum possible number of points from the given set which can simultaneously lie on the grid after its translation by some vector. \InputFile The first line of input contains two integers \textbf{N} and \textbf{K}. The \textbf{i}-th of the next \textbf{N} lines contains numbers \textbf{X_i}, \textbf{Y_i} --- the coordinates of the \textbf{i}-th point (\textbf{1} ≤ \textbf{N} ≤ \textbf{10^5}, \textbf{2} ≤ \textbf{K} ≤ \textbf{10^9}). The points' coordinates are integers and do not exceed \textbf{10^9} by absolute value. No two points coincide. \OutputFile Output the maximal possible number of points from the given set which can simultaneously lie on the grid.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
6 2
2 0
0 1
2 2
3 3
3 2
4 1
Output example #1
5

Example description: One of the optimal translation vectors in the given example is — (1,0).

Author Eldar Bogdanov
Source Winter School, Kharkov, 2011, Day 7