QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#13519. Tomki

Statistics

The software used in the Algorithm Busters competition is the work of Tomek W. This year, Tomek M. is in charge of it. Tomek M. is trying very hard to ensure the competition runs flawlessly. This is why Tomek has been having nightmares lately. Yesterday, he dreamed that he was a knight jumping on an infinite chessboard. The moves the knight can make are described by two pairs of integers: $(a, b)$ and $(c, d)$ — a knight standing on square $(x, y)$ can move to square $(x + a, y + b)$, $(x - a, y - b)$, $(x + c, y + d)$, or $(x - c, y - d)$. Tomek wondered (in his dream, of course) for which square $(x, y)$ other than $(0, 0)$, which he can reach starting from $(0, 0)$ (possibly in many jumps), the value $|x| + |y|$ is the smallest. Tomek woke up drenched in sweat because he could not solve this problem and did not know if he would wander so far from the point $(0, 0)$ that he would not have time to prepare the final round of the Algorithm Busters.

Task

Your task is to write a program that:

  • reads from standard input two pairs of integers $(a, b)$ and $(c, d)$, not equal to $(0, 0)$, describing the knight's moves,
  • determines a pair of integers $(x, y)$ other than $(0, 0)$ that the knight can reach (possibly in many jumps) from $(0, 0)$ and for which the value $|x| + |y|$ is the smallest,
  • writes the value $|x| + |y|$ to standard output.

Input

The first line of standard input contains four integers: $a$, $b$, $c$, and $d$, where $-100\,000 \le a, b, c, d \le 100\,000$.

Output

Your program should write to standard output, in the first and only line, a single integer equal to $|x| + |y|$.

Examples

Input 1

13 4 17 5

Output 1

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.