Kady is very energetic guy and he is fond of jumping. He is standing on a two dimension plane of size m*n
square units. Plane is partitioned into unit squares. So in total there are m*n
squares. Kady has his favourite number 'X'
, so each time when he will jump he will take jump of 'X'
units.
In short, plane can be considered as a 2D matrix. Kady is currently standing at position S(p,q)
where p
is p^th
row of matrix and q
is q^th
column of matrix. Kady wants to go from his position S
to new position R(u,v)
by taking jumps of exactly X
units each time.
Determine if kady can reach his destination or not. If he can reach, print the minimum number of jumps he need to take to go from S
to R
.
Note:
- Kady cannot go out of plane. If he do so then he will fall off the plane and dies.
- If Kady wants to take jump from point
A
toB
then jump is only feasible if Euclidean distance between these two points isX
.
Function Description
Complete the function minimumJumps
in the editor.
minimumJumps
has the following parameters:
int m
: the number of rows in the planeint n
: the number of columns in the planeint X
: Kady's favourite number, the jump distanceint p
: the row number of Kady's starting positionint q
: the column number of Kady's starting positionint u
: the row number of Kady's destinationint v
: the column number of Kady's destination
Returns
int
: the minimum number of jumps required to reach the destination or -1
if it's not possible
Example 1:
Input: m = 6, n = 5, X = 5, p = 1, q = 2, u = 6, v = 2
Output: 2
Explanation:In starting Kady is standing at position (1,2). From here he can jump to point (6,2) by taking 5 units of jump. From (6,2) he can go to (2,5) which is also at a distance of 5 units from his position.
Therefore, the minimum number of jumps required is 2.
1 ≤ m, n ≤ 1000
1 ≤ X ≤ 1000
1 ≤ p, u ≤ m
1 ≤ q, v ≤ n

input:
output: