Monument
Time limit2sMemory limit1024 MB
Given an axis-parallel polygon and staggered 1 x k tiles, shift the polygon to minimize the number of tiles it touches and print that count.
Problem
One of the central squares of Arkhangelsk is paved with rectangular tiles of size . Introduce a coordinate system so that the lower left corner of one tile has coordinates . Then the lower left corners of all tiles have coordinates for all integers and .
The square will host a monument to Stepan Pisakhov, a well-known writer and painter from Arkhangelsk. To install the monument, every tile that fully or partially lies under its base must be removed. The base of the monument is a polygon with integer vertex coordinates, and all of its sides are parallel to the coordinate axes. Any line parallel to one of the axes that crosses the base meets the base in a single segment. The monument must be placed so that the number of removed tiles is as small as possible. When choosing the place, the base may only be moved parallel to the coordinate axes. Write a program that computes the minimum number of tiles that must be removed.
Input
The first line contains two integers and , the number of vertices of the base and the size of a tile. Each of the next lines contains two integers and , the coordinates of the -th vertex of the base. The vertices are listed in counterclockwise order.
Output
Print a single line containing the minimum possible number of tiles that must be removed to place the monument on the square.
Hint
The original position of the base in the first input.
The optimal position of the base in the first input.