atcoder#ABC135E. [ABC135E] Golf

[ABC135E] Golf

Score : 500500 points

Problem Statement

Jumbo Takahashi will play golf on an infinite two-dimensional grid.

The ball is initially at the origin (0,0)(0, 0), and the goal is a grid point (a point with integer coordinates) (X,Y)(X, Y). In one stroke, Jumbo Takahashi can perform the following operation:

  • Choose a grid point whose Manhattan distance from the current position of the ball is KK, and send the ball to that point.

The game is finished when the ball reaches the goal, and the score will be the number of strokes so far. Jumbo Takahashi wants to finish the game with the lowest score possible.

Determine if the game can be finished. If the answer is yes, find one way to bring the ball to the goal with the lowest score possible.

What is Manhattan distance?

The Manhattan distance between two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is defined as x1x2+y1y2|x_1-x_2|+|y_1-y_2|.

Constraints

  • All values in input are integers.
  • 1K1091 \leq K \leq 10^9
  • 105X,Y105-10^5 \leq X, Y \leq 10^5
  • (X,Y)(0,0)(X, Y) \neq (0, 0)

Input

Input is given from Standard Input in the following format:

KK

XX YY

Output

If the game cannot be finished, print -1.

If the game can be finished, print one way to bring the ball to the destination with the lowest score possible, in the following format:

ss

x1x_1 y1y_1

x2x_2 y2y_2

..

..

..

xsx_s ysy_s

Here, ss is the lowest score possible, and (xi,yi)(x_i, y_i) is the position of the ball just after the ii-th stroke.

11
-1 2
3
7 4
2 10
-1 2
  • The Manhattan distance between (0,0)(0, 0) and (7,4)(7, 4) is 07+04=11|0-7|+|0-4|=11.
  • The Manhattan distance between (7,4)(7, 4) and (2,10)(2, 10) is 72+410=11|7-2|+|4-10|=11.
  • The Manhattan distance between (2,10)(2, 10) and (1,2)(-1, 2) is 2(1)+102=11|2-(-1)|+|10-2|=11.

Thus, this play is valid.

Also, there is no way to finish the game with less than three strokes.

4600
52 149
-1
4
9 9
5
1 3
4 2
4 6
6 8
9 9