This page is still under construction.

Parts of this page are still being built. What you see may change.

Mowing the Field

Time limit5sMemory limit512 MB

Summary
Count interior crossings of perpendicular mower segments cut at least T days apart.
Level

Hard8 of 10

Topics
Segment tree, Geometry, Sliding window
Solved
No attempts yet

Problem

Farmer John runs his farm well in almost every way, except that he is always late with the mowing. He moves the mower only once a day. On day 1 he starts at (x1,y1)(x_1, y_1), and on day dd he mows along a straight segment from the previous day's position to (xd,yd)(x_d, y_d). On the 2D map of the farm every move is horizontal or vertical, so xd=xd−1x_d = x_{d-1} or yd=yd−1y_d = y_{d-1}. John alternates horizontal and vertical moves on successive days.

He works so slowly that grass he already cut grows back before he is done. Grass cut on day dd reappears on day d+Td + T, so whenever his path meets a segment he cut at least TT days earlier, he cuts the same spot a second time. John wants to know how bad his routine is, so he wants to count how often that happens.

Count the crossing points where John re-cuts grass that had grown back. Only perpendicular meetings count, meaning a point shared by a horizontal segment and a vertical segment that is an endpoint of neither segment.

Input

The first line contains NN (2≤N≤100 0002 \le N \le 100\,000) and TT (1≤T≤N1 \le T \le N, TT even).

Each of the next NN lines gives the position of the mower on days 11 through NN. Line ii contains the integers xix_i and yiy_i, both between 00 and 10910^9.

Two consecutive positions may be equal. The move on such a day is a single point and takes part in no crossing.

Output

Print the number of crossing points described above.

Hint

In the first example the path of day 7 meets the segment cut on day 2. The two days are T=4T = 4 or more apart, so this crossing counts. The other two crossings are only 3 days apart and do not count.

Examples2

  1. Example 1

    Input
    7 4
    0 10
    10 10
    10 5
    3 5
    3 12
    6 12
    6 3
    
    Expected output
    1
    
  2. Example 2

    Input
    5 2
    0 4
    8 4
    8 8
    4 8
    4 0
    
    Expected output
    1