cho.sh
Notes
Loading...

Heewon's New York Life

Time limit

1s

Memory limit

128 MB

Problem

Manhattan's roads lie on an integer coordinate grid.

  • For every integer Z, an avenue is the line x = Z.
  • For every integer Z, a street is the line y = Z.
  • Broadway is the line Px + Qy = R.

Heewon wants to travel from one grid corner A(Ax, Ay) to another grid corner B(Bx, By). If only avenues and streets are used, the shortest distance between the two points is |Ax - Bx| + |Ay - By|.

During the trip, roads may be changed only at points where roads intersect. Considering every usable road, including Broadway, find the length of the shortest route from A to B.

Input

The input first gives Ax Ay Bx By. Here A = (Ax, Ay) and B = (Bx, By).

Then three numbers P Q R are given for Broadway. Broadway's equation is Px + Qy = R.

Output

Print the shortest distance from A to B. An absolute or relative error of at most 10^-9 is accepted.