Eclipsing Gianik Star

Gianik is a giant pink star in Canis Major constellation at an approximate distance of 700 light years from our Solar System. Each planet of Gianik’s planetary system follows a trajectory described by a circular orbit centered at Gianik, whose coordinates (x(t), y(t)) at time t obeys the parametric equations x (t) = ρ · cos (α + β·t) y (t) = ρ · sin (α + β·t) where ρ is a positive integer denoting the radius of the circular orbit, and α + β·t is a linear function with integer coefficients α,β describing the angle subtended by the planet’s trajectory from time 0 to time t. All angles are measured in degrees (◦), where one full rotation around Gianik takes 360◦. An eclipse occurs when Gianik and two distinct planets are located at collinear coordinates at the same time t, so that Gianik is not visible from the farthest planet because it is eclipsed by the other planet. May you determine the minimum non-negative integer t such that an eclipse occurs at time t? Input The input consists of several test cases. The first line of each test case contains a single integer N indicating the number of planets of Gianik’s planetary system (2 ≤ N ≤ 300). Each of the next N lines contains three blank-separated integers ρ, α and β, indicating the parameters that describe the planet’s trajectory around Gianik according to the statement (1 ≤ ρ ≤ 1000, −1000 < α < 1000, −1000 < β < 1000). You may assume that the orbits of all N planets have distinct radiuses. Output For each test case, print a single line with a non-negative integer indicating the minimum time in which an eclipse occurs in Gianik’s planetary system. If no eclipse occurs at any non-negative time, then print the text ‘GIANIK IS NEVER ECLIPSED’. Sample Input 2 10 90 2 20 0 4 2 10 90 4 20 0 2 2 10 90 2 20 0 2 Sample Output 45 135 GIANIK IS NEVER ECLIPSED