At the harbour of Barcelona

Professor Oak is attending some programming trainings at the harbour of
Barcelona. It is the first day and Prof. Oak is a bit sleepy, so he
decides to take a walk by the nearby beach. But, absorbed by the
difficulty of the problems, he gets too close to the sea. And, when he
realizes it, it is already too late. He starts running, but a large wave
reaches his feet, making him fall. Even worse, dozens of turists start
making fun of him. How humiliating...

Later, Prof. Oak is still drying his clothes, laughing at himself. “If
at least something good could come out of this...”, he thinks. “Well, of
course, a programming problem!” This one:

Consider Prof. Oak as a point located on the origin of an infinite
two-dimensional flat world. There are n sea waves surrounding him, each
one modeled as a circle with center (x_(i), y_(i)), initial radius
r_(i), and propagation speed s_(i), so that the radius of wave i as a
function of the time t ≥ 0 is r_(i) + s_(i) ⋅ t. Prof. Oak will choose
any fixed direction and run “forever” at speed p. Will he be able to
scape?

Input

Input consists of several cases, each with p and n, followed by n
quadruples with x_(i), y_(i), r_(i) and s_(i). Assume 1 ≤ p ≤ 1000,
3 ≤ n ≤ 10⁴, −1000 ≤ x_(i) ≤ 1000, −1000 ≤ y_(i) ≤ 1000,
1 ≤ r_(i) ≤ 1000, and 0 ≤ s_(i) < p. Except for n, all numbers are real,
with at most three digits after the decimal point. Initially, Prof. Oak
is strictly outside all the waves.

Output

For every case, print “safe” if Prof. Oak can escape, and “xof!”
otherwise. The input cases do not have precision issues.

Observation

For your computations, use the type long double. And good luck!

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:58:25.529Z

© Jutge.org, 2006–2026.
https://jutge.org
