DMOPC '19 Contest 4 P4 - Math Class

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type

Veshy is taking a class in linear algebra! He comes across a problem about the rotations of points with respect to the origin. However, he deems this too trivial so he comes up with the following problem instead:

Veshy chooses two points located at integer coordinates, and , on the 2D plane. There is initially a token at . Veshy also has a sequence of points, all located at integer coordinates, on this plane, . One operation is defined as choosing some index and rotating the token by an arbitrary angle around . However, if Veshy previously performed an operation on index , he is only allowed to perform an operation on index if . Determine if it's possible to move the token from to , and if so, the minimum number of operations required.

Constraints

The absolute value of all coordinates will be less than or equal to .

Input Specification

The first line contains one integer, .
The second line contains two space-separated integers, and , the coordinates of point .
The third line contains two space-separated integers, and , the coordinates of point .
The next lines contain two space-separated integers, and the coordinates of point .

Output Specification

Output one line containing one integer, the minimum number of operations if it's possible and -1 otherwise.

Sample Input

3
0 0
4 0
1 0
2 3
3 0

Sample Output

1

Explanation for Sample Output

One sequence of operations would be to rotate the token around and then another around . This sequence is shown in green. This would require two operations.
Another sequence would be rotating the token counter-clockwise around . This sequence is shown in blue. This would require one operation and it can be shown that there is no shorter sequence.