PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000148. Những điểm có độ trội đặc biệt (Weird Points)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những điểm có độ trội đặc biệt (Weird Points)

Weird Points

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn distinct points with integer coordinates (xi,yi)(x_i,y_i). A point PP dominates another point QQ when xP≥xQx_P\ge x_Q and yP≥yQy_P\ge y_Q. Points are compared only against other points, never themselves.

Let did_i be the number of other points dominated by point ii. The number of points not dominated by it is n−1−din-1-d_i. Its dominance score is

Di=∣di−(n−1−di)∣=∣2di−(n−1)∣.D_i=|d_i-(n-1-d_i)|=|2d_i-(n-1)|.

A point is weird if Di≥kD_i\ge k. Count the weird points.

Input

The first line contains n,kn,k. Each of the next nn lines contains one point (xi,yi)(x_i,y_i). The PHOJ version uses one test case per program run.

Output

Print one integer: the number of points with dominance score at least kk.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤k≤n0\le k\le n; 1≤xi,yi≤1091\le x_i,y_i\le 10^9; all coordinate pairs (xi,yi)(x_i,y_i) are distinct.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 0≤k≤n0\le k\le n; 1≤xi,yi≤1091\le x_i,y_i\le 10^9; all coordinate pairs (xi,yi)(x_i,y_i) are distinct.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 0≤k≤n0\le k\le n; 1≤xi,yi≤1091\le x_i,y_i\le 10^9; all coordinate pairs (xi,yi)(x_i,y_i) are distinct.

Examples

Example 1

Input

4 2
3 1
7 5
2 8
6 7

Output

2

Explanation

The numbers of other points dominated by the four points are 0,1,0,10,1,0,1. With n=4n=4, each has 3−d3-d nondominated points; the scores ∣2d−3∣|2d-3| are 3,1,3,13,1,3,1. Exactly two scores are at least 2.

Example 2

Input

3 1
1 1
2 2
3 3

Output

2

Explanation

Point (1,1)(1,1) dominates none, (2,2)(2,2) dominates one, and (3,3)(3,3) dominates both other points. With d=0,1,2d=0,1,2, scores are 2,0,22,0,2, so two points meet k=1k=1.