Under construction

Still being built. Things may change

Festival Decorating

Time limit9sMemory limit2048 MB

Summary
For each distance d, find the lowest-index lamp that has a lamp at x plus d with a different color, or print 0 if none exists.
Level

Hard8 of 10

Topics
Math, Array
Solved
No attempts yet

Statement

To celebrate the coming winter festival in Byteland, the main street is decorated with nn colorful lamps. The street can be regarded as the x-axis. The lamps are labeled 1,2,…,n1, 2, \ldots, n. The ii-th lamp is at x-coordinate xix_i and has color cic_i. No two lamps share the same x-coordinate.

You will be given qq queries. In the ii-th query, you are given an integer did_i (1≤di≤2500001 \le d_i \le 250000). Find the lamp uu (1≤u≤n1 \le u \le n) with the minimum index such that another lamp is located at xu+dix_u + d_i and its color differs from cuc_u. If no such uu exists, the answer is impossible to find.

Input

The first line contains two integers nn and qq (1≤n,q≤2500001 \le n, q \le 250000). Each of the next nn lines contains xix_i and cic_i (1≤xi≤2500001 \le x_i \le 250000, 1≤ci≤n1 \le c_i \le n). Each of the next qq lines contains one integer did_i.

Output

For each query, print one line containing the minimum index uu. If no such uu exists, print 00. An answer is correct if its absolute or relative error does not exceed 0.50.5. That is, for your answer uu and the jury's answer u′u', the answer is accepted when ∣u−u′∣max⁡(1,∣u′∣)≤0.5\frac{|u - u'|}{\max(1, |u'|)} \le 0.5. You may print a non-integer.

Examples1

  1. Example 1

    Input
    4 5
    3 1
    1 2
    5 1
    6 2
    1
    2
    3
    4
    5
    
    Expected output
    3
    2
    1
    2
    0