Simulate a two-wheeled buggy through N timed wheel-speed instructions and print the final axle position to five decimals.
Medium5GeometrySimulationMathNo attempts yetTime limit8sMemory limit512 MBThe car maker International Car Production Company (ICPC) is developing a new vehicle called Two-Wheel Buggy. As the name says, the vehicle has only two wheels. The buggy is made of a left wheel, a right wheel, and an axle, which is a bar joining the two wheels.

Figure 1: The basic structure of the buggy
Before building a prototype, the company decided to run a computer simulation. The rules of the simulation are below.
The buggy moves on the x-y plane. Let D be the distance from the center of the axle to each wheel. When the simulation starts, the center of the axle is at (0,0), the left wheel is at (−D,0), the right wheel is at (D,0), and the buggy faces the positive y direction. Both wheels have radius 1.

Figure 2: The initial position of the buggy
A sequence of instructions controls the movement of the buggy. One instruction is three numbers, Lspeed, Rspeed, and time. Lspeed and Rspeed are the rotation speeds of the left wheel and the right wheel in degrees per second, and time is how many seconds the two wheels keep those speeds. A positive speed turns a wheel in the direction that drives the buggy forward, and a negative speed turns it the other way. For example, with Lspeed set to −360, the left wheel makes one full turn per second in the direction that drives the buggy backward. You can set Lspeed and Rspeed to different values, and the buggy then turns left or right. You can also set one of them positive and the other negative. The buggy then spins around.

Figure 3: Examples of movement
Write a program that computes the final position of the buggy for a given instruction sequence. Assume the wheels have no width and never slip.
The input holds several datasets. Each dataset has the form below.
N D
Lspeed_1 Rspeed_1 time_1
...
Lspeed_N Rspeed_N time_N
The first line of a dataset holds two positive integers N and D (1≤N≤100, 1≤D≤10). N is the number of instructions, and D is the distance from the center of the axle to each wheel. Each of the next N lines holds three integers Lspeedi, Rspeedi, and timei (−360≤Lspeedi,Rspeedi≤360, 1≤timei) describing the i-th instruction. The sum of timei within one dataset is at most 500.
A line holding two zeros marks the end of the input. That line is not a dataset, so do not process it.
For each dataset, print the final position of the center of the axle on two lines. Print the x-coordinate on the first line and the y-coordinate on the second line. Round both coordinates to exactly five digits after the decimal point. When a rounded coordinate is zero, print 0.00000 and not -0.00000. Print no other characters.