Skip to main content
LIVE CONTEST: ALGOR Contest: Round #4 (Special Challenge) is live now!

~/algor $ cat problems/kesmadagi-butun-nuqtalar

Lattice points on a segment

Easy 1000 ms 128 MB 27%
Share

A segment $AB$ with endpoints $A(x_{1}; y_{1})$ and $B(x_{2}; y_{2})$ is given. How many points with both coordinates integer lie on the segment (including its endpoints)? Points $A$ and $B$ may coincide.

A segment on a grid; the lattice points lying on it are highlighted

Input

One line with four integers: $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$.

Output

One integer — the number of lattice points.

Note

$-10^{9} \le x_{1}, y_{1}, x_{2}, y_{2} \le 10^{9}$

Examples

Input #1
1 1 7 4
Output #1
4
Input #2
0 0 3 5
Output #2
2

Sign in to submit a solution

Signing up is free and takes a minute.