As a preliminary step in building an autonomous-vehicle system, your team must show that a central traffic controller can raise an alert whenever two cars are likely to collide unless someone takes corrective action.
The test course is a set of straight tracks that cross one another at various angles. As a car passes a sensor mounted on a track, its position and speed are recorded and sent to the controller, which keeps the two most recent readings for each car.
The process carries some built-in uncertainty: the sensor readings are not exact, and the sensors cannot tell whether a driver is already aware of the other traffic. The controller can almost never prove that a collision is unavoidable, and even if it could, it would rarely do so in time for the drivers to react.
We therefore want the controller to raise an alert whenever two cars will pass dangerously close to each other at any moment during the next 30 seconds, assuming both keep behaving as they were most recently observed to behave. Two cars are dangerously close if they pass within 18 ft of each other, and safe if their closest approach is at least 20 ft. A closest approach between 18 ft and 20 ft is ambiguous and may be reported either way.
Assume that:
If a car with initial speed $s_0$ has constant acceleration $a$, then after a time interval $t$ its speed is
$$s_t = a,t + s_0$$
and over that same interval it travels a distance
$$d = \frac{a}{2},t^2 + s_0,t.$$
The two exceptions to the constant-acceleration rule are:
The input contains one or more data sets.
Each data set has 4 observations, one per line. The first two observations belong to car 1 and the last two belong to car 2. Each observation is four floating-point numbers $t$, $x$, $y$, $s$:
No data set has a closest approach that falls in the ambiguous 18–20 ft range. For each car the two observations happen at distinct times, and the earlier observation is listed first.
The input ends with one observation made of 4 negative numbers, which is not part of any data set.
For each data set, print one line — either Dangerous or Safe — according to whether a dangerously close passage is predicted within the 30 seconds following the largest of the 4 observation times.