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

#PS0000243. Nhiệt độ pha cà phê (Karen and Coffee)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Nhiệt độ pha cà phê (Karen and Coffee)

Karen and Coffee

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Each of nn coffee recipes recommends every integer temperature in its inclusive interval [li,ri][l_i,r_i]. A temperature qualifies if at least kk recipes recommend it. For each inclusive query [a,b][a,b], count qualifying integer temperatures in that interval.

Input

First line: n,k,qn,k,q. The next nn lines contain li,ril_i,r_i, followed by qq lines containing a,ba,b.

Output

Print one integer per query, on a separate line.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤1001\le k\le n\le 100; 1≤q≤1001\le q\le 100; 1≤li≤ri≤1001\le l_i\le r_i\le 100; 1≤a≤b≤1001\le a\le b\le 100.
  • Subtask 2 (30 points): 1≤k≤n≤2000001\le k\le n\le 200000; 1≤q≤2000001\le q\le 200000; 1≤li≤ri≤2000001\le l_i\le r_i\le 200000; 1≤a≤b≤2000001\le a\le b\le 200000; k=1k=1.
  • Subtask 3 (50 points): 1≤k≤n≤2000001\le k\le n\le 200000; 1≤q≤2000001\le q\le 200000; 1≤li≤ri≤2000001\le l_i\le r_i\le 200000; 1≤a≤b≤2000001\le a\le b\le 200000.

Example 1

Input

3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100

Output

3
3
0
4

Explanation

The qualifying temperatures are 92, 93, 94, 97; intersections yield 3,3,0,4.

Example 2

Input

2 1 1
1 1
200000 200000
90 100

Output

0

Explanation

Neither 1 nor 200000 belongs to [90,100].