Stevie : " The second half of a programming contest is just as important as the second half of a football match, it's the decisive part ". So, here you are presumably having got over the first half. Also, let's not forget this guy who has given us some real memories to cherish :
You are given N segments [L,R], where L≤R . Now, you need to answer some queries based on these segments.
Overall, you need to answer Q queries. In each query you shall be given 2 integers K and X. You need to find the size of the Kth smallest segment that contains point X.
If no K segments contain point X , print 1 instead as the answer to that query.
A segment [L,R] is said to contain a point X, if L≤X≤R . When we speak about the Kth smallest segment, we refer to the one having the Kth smallest size. We define the size of a segment to be the number of integral points it contains, i.e. R+1−L
Input Format :
The first line contains a single integer N,
Each of the next N lines contains 2 space separated integers, where the 2 integers on the ith line denote the start and end points of the ith segment given to you.
The next line contains a single integer Q.
Each of the next Q lines contains 2 space separated integers K and X.
Output Format :
Print the ansnwer to each query on a new line.
Constraints :
1≤N,Q≤2×105
1≤Li≤Ri≤109 ,where 1≤i≤N
1≤K≤N
1≤X≤109
For the second query, the 4th smallest segment containing the point 2 is segment 1...9.
Similarly, for the first query, the 2nd smallest segment containing point 4 is the segment 4...8