cswork / OAOpen practice workspace

IntuitOA #14

Jumping Kady (Intuit India)

Estimated MediumJudge-ready

Topics (AI-labelled)Shortest PathsBits & Math

On an m×n grid, every jump must cover exactly X units (Euclidean distance). Find the minimum number of jumps from the start to the target without jumping off the board; return -1 if the target is unreachable. The explanation of the fixed source example describes the target as (2,5), but its input mistakenly gave the intermediate point (6,2), so the example's u,v are corrected to 2,5.

Input

A single line with seven integers m n X p q u v: the number of rows, the number of columns, the jump distance, and the start and target coordinates. Ranges follow the source constraints.

Output

Output the minimum number of jumps; output -1 if the target is unreachable.

Example 1

Input:

6 5 5 1 2 2 5

Output:

2

Example 2

Input:

2 2 1 1 1 2 2

Output:

2

Example 3

Input:

6 5 5 1 2 1 2

Output:

0

Example notes

Precompute the integer offsets satisfying dr²+dc²=X², then run BFS over the board cells.

Editorial

Loading solution…