cambridge

Time limit: 1s Memory limit: 256MB Input: Output:

The admission interview at the prestigious University of Cambridge consist of NN tasks, numbered from 11 to NN. Alex is there right now, waiting to attend the interview. Takahiro Wong, who has just finished his interview, solved all the tasks. More precisely, he solved the ii-th problem after DiD_i seconds from the beginning of the interview.

Knowing the fact that he can solve the ii-th problem in TiT_i seconds, Alex asks himself MM questions: x yx \ y. For every question, Alex will consider only the tasks from the interval [x,y][x, y] and he wants to know whether he can solve each of these tasks before Takahiro Wong. (Alex can solve the tasks from the interval [x,y][x, y] in any order).

For example, let’s consider that Alex has to solve the tasks aa and bb (in this order). He will finish task aa after TaT_a seconds, and task bb after Ta+TbT_a + T_b seconds. Alex will solve both problems before Takahiro Wong if Ta<DaT_a < D_a and Ta+Tb<DbT_a + T_b < D_b.

Both Takahiro Wong and Alex will start their interviews at second 00.

Task

Help Alex answer correctly to all MM questions.

Input data

  • The first line of the standard input will contain NN and MM.
    • NN - the number of tasks
    • MM - the number of questions.
  • On the following NN lines, there will be TiT_i and DiD_i.
    • TiT_i - the time needed for Alex to solve the ii-th problem
    • DiD_i - the time (from the beginning of his interview) after Takahiro Wong will solve the ii-th problem.
  • On the following MM lines, there will be xx and yy, representing the interval [x,y][x, y].

Output data

The standard output will contain MM lines, the answers to the MM questions.

The ii-th line will contain:

  • 11, if Alex cand solve all the tasks from the interval [x,y][x,y] before Takahiro Wond
  • 00, otherwise.

Restrictions

  • 1Ti<Di1091 \leq T_i < D_i \leq 10^9
  • The DiD_i values are not distinct (there can be a value that appears multiple times)
  • Alex can’t solve 22 tasks in the same time, but Takahiro Wong can (The DiD_i values are not distinct).
# Points Restrictions
1 15 1N,M101 \leq N, M \leq 10
2 25 1NM1051 \leq N \cdot M \leq 10^5
3 15 1N1031 \leq N \leq 10^3, 1M1051 \leq M \leq 10^5
4 45 1N,M1051 \leq N, M \leq 10^5

Example

stdin

4 3
1 10
14 18
2 7
10 12
3 4
2 4
1 3

stdout

0
0
1

Explanation

The 33rd question refers to the interval [1,3][1,3]:

  • There are 66 ways Alex can solve the tasks: (1,2,3)(1,2,3), (1,3,2)(1,3,2), (2,1,3)(2,1,3), (2,3,1)(2,3,1), (3,1,2)(3,1,2), (3,2,1)(3,2,1).
  • If he solves the tasks in the order (1,3,2)(1,3,2), we have to fulfill the following relations: T1<D1T_1 < D_1, T1+T3<D3T_1 + T_3 < D_3 and T1+T3+T2<D2T_1 + T_3 + T_2 < D_2. We can see that all of them are true.
  • Because Alex found at least one way to solve all the problems before Takahiro Wong, the answer is 11 for the third question.

Log in or sign up to be able to send submissions!