Generalized Knights
On an infinitely large grid, a generalized knight stands at position $(0, 0)$. The knight is allowed to move in $8$ ways. First, it may move either $\pm a$ or $\pm b$ steps horizontally, and then $\pm a$ or $\pm b$ steps vertically.
Compute the minimum number of moves the knight must make to reach the position $(x, y)$.
Input
The first and only line contains the four integers $a, b, x, y$ from the statement ($1 \le a \neq b \le 10^{9}$, $0 \le x, y \le 10^9$). It is guaranteed that the knight can reach $(x, y)$, and $(x, y)$ is not $(0, 0)$.
Output
Output a single integer – the minimum number of moves from position $(0, 0)$ to $(x, y)$.
Sample Input 1 | Sample Output 1 |
---|---|
2 1 1 1 |
2 |
Sample Input 2 | Sample Output 2 |
---|---|
2 1 1 0 |
3 |
Sample Input 3 | Sample Output 3 |
---|---|
123 321 123456 321456 |
1036 |