Problem 112: Chicken on a Stick

(U.M. ACM Runoffs 2002, problem 5)

Description

      The chicken people of the planet Poultron have discovered that the higher above the ground they are, the further they can see. This is very exciting for them because they have also discovered that their planet is round. They have got the idea that if they stand on top of a high enough stick, they will be able to see the backs of their own heads. That would be an important thing because they care very much about their appearance, and have not yet discovered mirrors.

      Unfortunately, as everyone knows, if you stare into the eyes of a chicken, it is instantly hypnotised and falls into a trance. Not a problem unless you happen to be a chicken on top of a very high stick, in which case the fall is often fatal. So the chicken people want to make sure that they never erect their tall looking-sticks so close together that a chicken on top of one stick might see the eyes of a chicken on top of the other stick; the tops of the other looking-sticks must always be hidden below the horizon.

      Given the radius of the planet Poultron, the heights of the two looking-sticks, and the distance between their bases (measured as the "great circle distance", an arc over the surface of the planet), you must calculate whether the top of one stick is visible from the top of the other stick.

The inputs to your program will be multiple sets of the following four values:
      r, the radius of the planet,
      d, the surface arc distance between sticks,
      h1, the height (of a chicken's eye above the ground when on top) of the first stick,
      h2, the height (ditto) of the second stick.


      The units are always feet, and the inputs, which will always be between 1 and 1000000 have always been rounded to the nearest whole number. The distance between the two sticks will never be more than half of the circumference of the planet.

      There will be no marginal cases (on the cusp between visible and invisible) as atmospheric distortions would make the results meaningless.

      The input consists of multiple lines each bearing four numbers, there is no special indication for the end of the input file. For each input case, print one line saying either "safe" or "dangerous", as the case may be.

      Just to be sure the chickens haven't confused your understanding of physics, they were labouring under a misconception: they would never have been able to see the backs of their own heads. Even on Poultron light travels in straight lines.

Sample Input

10000 1000 1000 500
10000 31415 5000 5000

Sample Output

dangerous
safe

End of Problem