This page is still under construction.

Parts of this page are still being built. What you see may change.

Planet Defense

Time limit2sMemory limit256 MB

Summary
Given each asteroid's initial position and constant velocity, count for each queried integer time how many asteroids lie strictly within distance R of the origin.
Level

Hard8 of 10

Topics
Math, Sorting, Binary search, Geometry
Solved
No attempts yet

Problem

After a meteorite recently fell in the Ural region, the governments of many countries began thinking about how to protect the Earth from asteroids. For this purpose the International Anti-Meteorite Agency (IAMA) was created, and the best scientists in astrophysics were invited to join it.

Within a few weeks the scientists determined that n asteroids are flying in the immediate vicinity of the Earth, and that an asteroid poses no danger to the Earth if its distance from the Earth is strictly greater than R. For simplicity the scientists assumed that all asteroids near the Earth fly in straight lines, and they determined their positions and velocity vectors at time zero. Now the scientists want to be able to answer queries: how many asteroids pose a danger to the Earth at a given moment in time.

For convenience, we introduce a rectangular Cartesian coordinate system. Let the Earth have coordinates (0, 0, 0). All asteroids and the Earth are treated as point masses in space.

Several queries about specific moments in time are given. For each of them, determine how many asteroids at that moment pose a danger to the Earth.

Input

The first line contains two integers n and R (1 ≤ n ≤ 100000, 1 ≤ R ≤ 10^6): the number of asteroids and the radius of the danger zone.

Each of the following n lines contains six integers xi, yi, zi, vxi, vyi, vzi (−10^6 ≤ xi, yi, zi ≤ 10^6, −100 ≤ vxi, vyi, vzi ≤ 100): the initial position and velocity vector of the i-th asteroid. The velocity vector is guaranteed not to be zero.

The next line contains a single integer m (1 ≤ m ≤ 100000): the number of moments in time that interest the scientists.

Each of the following m lines contains a single integer ti (0 ≤ ti ≤ 10^7): a moment in time that interests the scientists.

Output

For each moment in time, output a single integer: the number of asteroids inside the danger zone.

Examples1

  1. Example 1

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