Under construction

Still being built. Things may change

Monument

Time limit2sMemory limit1024 MB

Summary
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.
Level

Medium7 of 10

Topics
Geometry, Math, Sorting
Solved
No attempts yet

Problem

One of the central squares of Arkhangelsk is paved with rectangular tiles of size 1×k1 \times k. Introduce a coordinate system so that the lower left corner of one tile has coordinates (0,0)(0, 0). Then the lower left corners of all tiles have coordinates (i⋅k+j,j)(i \cdot k+j,j) for all integers ii and jj. 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 nn and kk, the number of vertices of the base and the size of a tile. Each of the next nn lines contains two integers xix_i and yiy_i, the coordinates of the ii-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.

Examples1

  1. Example 1

    Input
    12 3
    2 3
    1 3
    1 2
    3 2
    3 1
    8 1
    8 2
    10 2
    10 3
    8 3
    8 4
    2 4
    
    Expected output
    7