시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
3 초 1024 MB 12 10 8 80.000%

문제

N students took an examination, which consisted of mathematics and informatics sections. The i-th student (1 ≤ i ≤ N) scored S i points in mathematics, and Ti points in informatics. Professor T and Professor I are going to decide whether each student passes or fails, based on the scores.

  • Professor T regards both subjects as important; he wants students who scored at least A points in mathematics and B points in informatics to pass.
  • Professor I regards only the overall score as important; he wants students who scored at least C points in total to pass.
  • Only students whom both professors want to pass can pass the examination.

You do not know these criteria: the values of A, B and C. Instead, given Q triplets of integers (Xj, Yj, Zj) (1 ≤ j ≤ Q), you want to know the number of students passing the examination when A = Xj, B = Yj and C = Zj.

Write a program which, given the number of students, each student’s scores, and some criteria, calculates the number of students passing the examination under each criterion.

입력

Read the following data from the standard input. All the values in the input are integers.

N Q
S1 T1
.
.
.
SN TN
X1 Y1 Z1
.
.
.
XQ YQ ZQ

출력

Write Q lines to the standard output. The j-th line (1 ≤ j ≤ Q) should contain the number of students passing the examination when A = Xj, B = Yj and C = Zj.

제한

  • 1 ≤ N ≤ 100 000.
  • 1 ≤ Q ≤ 100 000.
  • 0 ≤ Si ≤ 1 000 000 000 (1 ≤ i ≤ N).
  • 0 ≤ Ti ≤ 1 000 000 000 (1 ≤ i ≤ N).
  • 0 ≤ Xj ≤ 1 000 000 000 (1 ≤ j ≤ Q).
  • 0 ≤ Yj ≤ 1 000 000 000 (1 ≤ j ≤ Q).
  • 0 ≤ Zj ≤ 2 000 000 000 (1 ≤ j ≤ Q).

예제 입력 1

5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100

예제 출력 1

2
4
1
1
  • When A = 20, B = 50 and C = 120, only the 1st and the 2nd student can score at least 20 points in mathematics, at least 50 points in informatics, and at least 120 points in total. Therefore, the number of students passing the examination is 2.
  • When A = 10, B = 10 and C = 100, only the 1st, the 2nd, the 4th and 5th student can score at least 10 points in mathematics, at least 10 points in informatics, and at least 100 points in total. Therefore, the number of students passing the examination is 4.
  • When A = 60, B = 60 and C = 80, only the 2nd student can score at least 60 points in mathematics, at least 60 points in informatics, and at least 80 points in total. Therefore, the number of students passing the examination is 1.
  • When A = 0, B = 100 and C = 100, only the 1st student can score at least 0 points in mathematics, at least 100 points in informatics, and at least 100 points in total. Therefore, the number of students passing the examination is 1.

예제 입력 2

10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117

예제 출력 2

1
3
5
8
8
3
3
3
5
6