Travel Guide

Time limit2sMemory limit128 MB

Summary
Find the minimum time for a guide starting at the origin to intercept N moving tourists in some order and send them home, then return herself.
Level

Hard9 of 10

Topics
Brute force, Binary search, Geometry, Math
Solved
No attempts yet

Problem

Yoonhwa is a travel guide who leads tourists on a bus. One day, she is guiding NN tourists.

During a one-hour lunch break, each tourist goes wherever they want. At the end of the break, no tourist has returned to the bus. Yoonhwa starts from the bus, must meet every tourist, tell them to return immediately, and then return to the bus herself.

At time t=0t = 0, the bus is at the origin (0,0)(0, 0). Each tourist keeps moving in a straight line from their current position with their own speed and direction. When Yoonhwa meets a tourist, that tourist immediately changes direction and moves straight back to the bus at the same speed.

Find the minimum possible time at which everyone, including Yoonhwa, has arrived back at the bus.

Input

The first line contains the number of tourists NN (1≤N≤8)(1 \le N \le 8).

The second line contains Yoonhwa's speed as a decimal number.

Each of the next NN lines contains four decimal numbers xix_i, yiy_i, viv_i, and aia_i.

  • (xi,yi)(x_i, y_i) is the position of the ii-th tourist at time t=0t = 0 (−106≤xi,yi≤106)(-10^6 \le x_i, y_i \le 10^6).
  • viv_i is that tourist's speed (1≤vi≤100)(1 \le v_i \le 100).
  • aia_i is that tourist's movement direction in radians (1≤ai≤2π)(1 \le a_i \le 2\pi), measured counterclockwise from the positive xx-axis.

Output

Print the minimum time, rounded to the nearest integer.

The answer is guaranteed to be at most 10610^6.

Examples1

  1. Example 1

    Input
    3
    100.0
    40.0 25.0 20.0 5.95
    -185.0 195.0 6.0 2.35
    30.0 -80.0 23.0 2.76
    Expected output
    51