Score : 500 points

Problem Statement

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

The ball is initially at the origin (0, 0), and the goal is a grid point (a point with integer coordinates) (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 K, 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 (x_1, y_1) and (x_2, y_2) is defined as |x_1-x_2|+|y_1-y_2|.