Grădinarul Hu

Time limit: 0.2s Memory limit: 64MB Input: Output:

Hu’s Garden can be visualized as a Cartesian coordinate system. He wants to choose a triangle from his garden in which to plant more flowers. He has already decided on two of the lines that form the triangle, and you must help him find the third one, knowing that he wants to plant exactly kk flowers and that flowers are planted at every point with integer coordinates inside and on the boundary of the triangle, and only at those locations. He also wants flowers to be planted at the vertices of the triangle.

Task

Formally, you are given a natural number nn, which represents the size of a 2D2D plane, and 22 lines defined by equations of the form y=ax+bcy = \frac{ax + b}{c}, where aa, bb, cc are natural numbers and c0c \not= 0. You must find 33 points (with integer coordinates) in the plane that form a triangle such that it contains kk lattice points (with integer coordinates) on its boundary or in its interior, and among the lines determined by the 33 vertices, 22 of them are the given ones.

Input Data

On the first line you will read, in order, 88 numbers: nn, kk, a1a_1, b1b_1, c1c_1, a2a_2, b2b_2, c2c_2; where nn is the size of the 2D2D plane, kk is the number of flowers inside the triangle, a1a_1, b1b_1 and c1c_1 are the parameters of the first line, and a2a_2, b2b_2 and c2c_2 are the parameters of the second line.

Output Data

If a solution exists, you must output 66 numbers separated by a space: x1x_1, y1y_1, x2x_2, y2y_2, x3x_3 and y3y_3, representing the coordinates of the 33 points. Otherwise, you must output 1-1.

Constraints

  • 1n1 000 0001 \leq n \leq 1 \ 000 \ 000
  • 0k2 000 000 0000 \le k \le 2 \ 000 \ 000 \ 000
  • 2 000 000 000a1,b1,c1,a2,b2,c22 000 000 000-2 \ 000 \ 000 \ 000 \le a_1, b_1, c_1, a_2, b_2, c_2 \le 2 \ 000 \ 000 \ 000
  • The plane is considered to have vertices at the points (0,0)(0, 0), (0,n)(0, n), (n,0)(n, 0) and (n,n)(n, n).
  • It is guaranteed that the given lines intersect at a single point and that this point is a lattice point with coordinates between 00 and nn.
  • The triangle must have all vertices distinct in order to be considered valid.
  • If multiple solutions exist, any of them may be output.
# Points Restrictions
1 10 n100n \leq 100
2 20 n500n \leq 500
3 30 n2 000n \leq 2 \ 000
4 40 No additional constraints

Example 1

stdin

10 6 1 5 1 0 6 1

stdout

1 6 0 5 5 6

Explanation

In the first example, a valid solution is (1,6)(1, 6), (0,5)(0, 5), (5,6)(5, 6). The first line is the one colored orange, the second one is colored blue, and in green we have the third line determined by two of the points. In red we have the lattice points inside and on the sides of the resulting triangle.

Another valid solution, defined by the points (1,6)(1, 6), (3,6)(3, 6) and (3,8)(3, 8), can be seen in the image below. The triangle defined by the 33 lines also contains k=6k = 6 lattice points.

Example 2

stdin

80 52 -1 80 8 1 0 2

stdout

16 8 8 9 34 17

Log in or sign up to be able to send submissions!