This page is still under construction.

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

Snails

Time limit1sMemory limit128 MB

Summary
Each of N snails moves in a fixed direction at speed 1 and stops at the fence, at any point an earlier snail crossed, or when it meets another snail simultaneously; find when the last snail stops.
Level

Hard8 of 10

Topics
Geometry, Simulation, Sorting, Implementation
Solved
No attempts yet

Problem

There are N snails inside a square fence. All snails start moving from their initial positions at the same time and follow these rules:

  1. Every snail's starting position is distinct.
  2. Each snail is given a single direction and moves only in a straight line along that direction.
  3. Every snail moves at the same speed of 1 cm per second.
  4. A snail stops when it reaches the fence (the boundary of the square).
  5. A snail stops as soon as it reaches a point that another snail has already passed through.
  6. If two or more snails reach the same point at the same time, all of them stop.

In other words, while a snail travels along its path it stops when it first (a) reaches the fence, (b) reaches a point that another snail passed through earlier than it, or (c) meets another snail at the same point at exactly the same time.

Given the starting position and direction of N snails that all start at the same instant, find the time it takes until the last snail stops. Round the answer at the third decimal place.

Input

The first line contains the number of snails NN (1≤N≤1,0001 \le N \le 1{,}000) and a natural number LL (10≤L≤10,00010 \le L \le 10{,}000), the length in cm of one side of the fence, separated by a space. The bottom-left corner of the fence is at (0,0)(0, 0) and the top-right corner is at (L,L)(L, L).

Each of the next NN lines contains four integers x,y,p,qx, y, p, q (0<x,y,p,q<L0 < x, y, p, q < L) describing one snail: the snail starts at (x,y)(x, y) and moves in a straight line in the direction from (x,y)(x, y) toward (p,q)(p, q). The points (x,y)(x, y) and (p,q)(p, q) are distinct.

Output

Print, on the first line, the time until all snails have stopped, rounded at the third decimal place. The time must always be shown to exactly two decimal places. For example, a time of 10.667 is printed as 10.67, a time of 5 as 5.00, and a time of 5.5 as 5.50.

Examples1

  1. Example 1

    Input
    9 15
    2 13 3 13
    6 10 5 11
    7 12 6 11
    13 14 12 11
    8 1 6 2
    6 4 10 5
    9 8 8 6
    10 4 9 5
    14 3 12 9
    
    Expected output
    10.67