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

#GD0000077. Phá hủy các bức tường (Destroyer Takahashi)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phá hủy các bức tường (Destroyer Takahashi)

Destroyer Takahashi

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn walls on distinct rows of a grid with 10910^9 columns. Wall ii occupies columns LiL_i through RiR_i, inclusive. One punch affects every row in DD consecutive columns starting at an integer xx with 1≤x≤109−D+11\le x\le10^9-D+1. A wall is destroyed if at least one of its columns is hit. Find the minimum number of punches.

Input

The first line contains n,Dn,D. Each of the following nn lines contains Li,RiL_i,R_i.

Output

Print the minimum number of punches.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤D≤1091\le D\le10^9; 1≤Li≤Ri≤1091\le L_i\le R_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤D≤1091\le D\le10^9; 1≤Li≤Ri≤1091\le L_i\le R_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤D≤1091\le D\le10^9; 1≤Li≤Ri≤1091\le L_i\le R_i\le10^9.

Examples

Input

3 3
1 2
4 7
5 9

Output

2

Explanation

A punch spanning columns 22–44 destroys the first two walls. A punch on columns 55–77 destroys the third. One punch cannot hit both the first and third walls, so two is optimal.