Model Rocket Height

Time limit1sMemory limit128 MB

Summary
Compute a model rocket's height above ground from three collinear observers' elevation angles, baseline spacing, and instrument height, using 3D geometry.
Level

Hard8 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

There are several ways to measure how high a model rocket rises. One method works as follows.

Observers A, B, and C stand on one straight line, with distance D between each adjacent pair. Each observer uses a theodolite mounted H units above the ground.

After launch, near its highest point, the rocket opens its parachute and releases a cloud of dust. Each observer measures the angle from the horizontal line to that dust cloud. If the angles measured by A, B, and C are a, b, and c, respectively, those values can be used to determine the rocket's height above the ground.

Given D, H, a, b, and c, write a program that computes the rocket's height rounded to the nearest integer.

Input

The first line contains decimal numbers D and H. They may be non-integers, and they are the same for every rocket observation.

Each following line contains the three angles a, b, and c, in degrees, for one rocket. The final line contains a value that is not positive and marks the end of the input. Except for the final line, every angle is greater than 0 degrees and less than 90 degrees.

Output

For each triple of angles, print the computed height rounded to the nearest integer, one result per line.

Examples1

  1. Example 1

    Input
    50 4
    43.88 46.85 40.70
    34.52 39.50 35.43
    27.05 29.22 26.14
    0 0 0
    
    Expected output
    90
    70
    60