Planet Hunting

No attempts yetTime limit1sMemory limit128 MB

Problem

Consider a fictitious solar system made up of a star SS, a planet PP, and its moon MM. Planet PP travels around star SS on a perfect circular orbit with a revolution period of exactly TT Earth days. Moon MM travels around planet PP on a perfect circular orbit whose revolution period is unknown.

Given the position of moon MM relative to star SS at three different times, your goal is to compute the distance from star SS to planet PP.

Work in a two-dimensional Cartesian coordinate system whose origin is star SS. Assume that PP's counterclockwise orbit around SS and MM's counterclockwise orbit around PP both lie entirely in the xyxy-plane. Let (x1,y1)(x_1, y_1) be the position of moon MM at the first observation, (x2,y2)(x_2, y_2) its position k1k_1 Earth days later, and (x3,y3)(x_3, y_3) its position k2k_2 Earth days after the second observation.

Input

The input contains several test cases. Each test case consists of two lines. The first line contains the integers TT, k1k_1, and k2k_2 with 1T,k1,k210001 \le T, k_1, k_2 \le 1000. The second line contains six floating-point values x1x_1, y1y_1, x2x_2, y2y_2, x3x_3, and y3y_3. The input points are chosen so that the solution is unique, and the final distance from planet PP to star SS is always within 0.10.1 of the nearest integer. The end of input is marked by a single line containing 0 0 0.

Output

For each test case, print the distance from planet PP to star SS, rounded to the nearest integer, on its own line.