Kingdom Trip

Find the shortest subsequence from the first to the last point so every skipped point lies within distance d of its shortcut segment.

Hard8Dynamic programmingGeometryNo attempts yetTime limit2sMemory limit256 MB

Problem

The kingdom is an infinite flat plane with no borders. It holds nn gathering locations.

The king wanted a closer look at his people, so he planned a trip through all of them with a speech at each one. The original plan is the polygonal chain p1p2pnp_1 \to p_2 \to \cdots \to p_n.

The king is old, so his assistants want to cut the number of speeches by skipping some locations. The new plan has to be a polygonal chain over a subsequence of pp that starts at p1p_1 and ends at pnp_n, that is, pi1pi2pimp_{i_1} \to p_{i_2} \to \cdots \to p_{i_m} with 1=i1<i2<<im=n1 = i_1 < i_2 < \cdots < i_m = n.

A location pjp_j with ik<j<ik+1i_k < j < i_{k+1} can be skipped only if the distance from pjp_j to the segment pikpik+1p_{i_k} p_{i_{k+1}} is at most dd. If that distance exceeds dd, the king refuses to drop the location.

Original route

New route

Find the new route with the smallest possible number of locations.

Input

The first line contains two integers nn and dd (2n20002 \le n \le 2000, 1d1061 \le d \le 10^6). Here nn is the number of locations in the original plan and dd is the largest distance allowed to a skipped location.

Each of the next nn lines contains two integers xix_i and yiy_i, the coordinates of location pip_i. The absolute value of each coordinate is at most 10610^6, and no two locations share the same coordinates.

Output

Print the smallest number of locations the king visits. The answer is guaranteed to be the same when dd grows or shrinks by 10410^{-4}.