Problem:
Score : 100 points

Problem Statement

Takahashi is drawing a segment on grid paper.

From a certain square, a square that is x squares to the right and y squares above, is denoted as square (x, y).

When Takahashi draws a segment connecting the lower left corner of square (A, B) and the lower left corner of square (C, D), find the number of the squares crossed by the segment.

Here, the segment is said to cross a square if the segment has non-empty intersection with the region within the square, excluding the boundary.

Constraints

1 \leq A, B, C, D \leq 10^9

At least one of A \neq C and B \neq D holds.

Input

The input is given from Standard Input in the following format:

A B C D

Output

Print the number of the squares crossed by the segment.

Sample Input 1

1 1 3 4

Sample Output 1

4

Sample Input 2

2 3 10 7

Sample Output 2

8

Solution in Fortran (gfortran v4.8.4) (judge verdict: Wrong Answer)

program segment_on_grid_paper
  implicit none
  integer :: a, b, c, d, x, y, y0, y1, i
  integer(8) :: m
  read(*,*) a, b, c, d
  x = abs(c-a)
  y = abs(d-b)
  y0 = 0
  m = 0_8
  do i = 1, x
    y1 = ceiling(real(y,8)*real(i,8)/real(x,8))
    m = m+int(y1-y0,8)
    y0 = floor(real(y,8)*real(i,8)/real(x,8))
  end do
  write(*,'(i0)') m
  stop
end program segment_on_grid_paper