We’re preparing your current view and syncing the latest data.
Inna is on an n by m grid, starting from cell (x,y). She can move by repeatedly jumping a fixed number of steps along rows and columns. Each move allows moving d steps simultaneously in both row and column directions (or zero in one direction). Determine the minimum number of moves required for Inna to reach at least one of the four corners of the grid: (1,1), (1,m), (n,1), or (n,m). If it is impossible, output -1.
The first line contains six integers n, m, x, y, and d (1 <= n,m <= 10^9, 1 <= x <= n, 1 <= y <= m, 1 <= d <= 10^9).
Output the minimum number of moves to reach a corner if possible; otherwise, output -1.
1 <= n,m <= 10^9 1 <= x <= n 1 <= y <= m 1 <= d <= 10^9
Example 1
Input
5 8 2 4 1
Output
3
Explanation
Inna can move from (2,4) to (1,1) in 3 moves of d=1 steps each.
Example 2
Input
10 10 2 2 3
Output
-1
Explanation
No corner is reachable using steps of size 3 starting from (2,2).