Under construction

Still being built. Things may change

Health in Hazard

Time limit3.5sMemory limit1024 MB

Summary
Given N half-plane cuts through a plane with a den at the origin, find the first cut after which no point on the circle of radius D is reachable.
Level

Hard8 of 10

Topics
Geometry, Binary search, Sorting
Solved
No attempts yet

Problem

In the frozen wilderness, a polar bear lives on a vast glacier, represented as a 2D plane. The bear's den is at (0,0)(0, 0). To stay healthy, each time the bear wakes up in its den, it walks to any point at distance exactly DD from the den. Distance is Euclidean.

Scientists received a report of predictions about how global warming will affect the glacier in the coming days. The predictions are in chronological order. Each one is an infinite line that marks a melting event. Once a prediction comes true, the bear cannot cross its line anymore.

At first the glacier is infinite in all directions, and the bear can roam freely. But the glacier may shrink until the bear can no longer be healthy. Find the earliest moment when no point at distance exactly DD from the den can be reached by the bear.

The figure shows the first test case. The circle contains the points at distance exactly DD from the den. With only the first three predictions (solid lines), the bear can still reach points on the circle. Once the fourth prediction (dashed line) is also considered, no point on the circle can be reached from the den.

Input

The first line contains an integer NN (1≤N≤2×1051 \le N \le 2 \times 10^5) and a rational number DD with at most five digits after the decimal point (1≤D≤1061 \le D \le 10^6). NN is the number of predictions, and DD is the distance from the den.

Each of the next NN lines contains four integers X1X_1, Y1Y_1, X2X_2, and Y2Y_2 (−106≤X1,Y1,X2,Y2≤106-10^6 \le X_1, Y_1, X_2, Y_2 \le 10^6, and (X1,Y1)≠(X2,Y2)(X_1, Y_1) \ne (X_2, Y_2)). They define the infinite line through (X1,Y1)(X_1, Y_1) and (X2,Y2)(X_2, Y_2). The bear cannot cross this line once the prediction comes true. The predictions are in chronological order and are numbered from 1 to NN in that order. No line passes through the den.

Output

Output a single line with the number of the earliest prediction after which no point at distance exactly DD from the den can be reached by the bear. If this never happens, output *. The answer does not change if DD varies by up to 10−510^{-5} from the given value.

Examples2

  1. Example 1

    Input
    5 4.321
    -2 -1 3 -2
    1 6 3 -2
    1 6 -2 -1
    -3 4 3 3
    -2 1 5 4
    
    Expected output
    4
    
  2. Example 2

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