LCC '22 Contest 1 S2 - Candy Hunting

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Bob, an experienced candy hunter, is trying to track down a particularly tricky piece of candy on Halloween. He knows that the candy is located at a single point (x, y, z) in 3-dimensional space, where x, y, and z are integers. However, he does not know the point's exact coordinates.

Luckily, Bob has two trusty gadgets that he can use to pinpoint the location of the candy. First, using his sweetness detector, he has determined that the point is at a distance of exactly R units away from the origin. In other words, its coordinates satisfy the equation x^2 + y^2 + z^2 = R^2. Next, using his sourness meter, he has determined that the point satisfies the formula (x, y, z) = (x_0 + t \cdot u_x, y_0 + t \cdot u_y, z_0 + t \cdot u_z), where t is an unknown real number.

Now, Bob needs your help to find the exact coordinates of the point, or that a unique point with integer coordinates cannot be found (his gadgets could be malfunctioning).

Input Specification

The first line of input will contain a single integer, R (1 \le R \le 1000).

The next line will contain three space-separated integers, x_0, y_0, and z_0 (|x_0|, |y_0|, |z_0| \le 1000).

The next line will contain three space-separated integers, u_x, u_y, and u_z (|u_x|, |u_y|, |u_z| \le 1000).

Output Specification

Output the values of x, y, and z separated by spaces on a single line.

If a single point with integer coordinates cannot be found, output -1 instead.

Sample Input 1

10
6 8 6
0 0 6

Sample Output 1

6 8 0

Sample Input 2

2
10 10 10
-9 1 8

Sample Output 2

-1

Comments

There are no comments at the moment.