Problem B. Автономная охрана

Author:М. Спорышев, А. Кленин   Time limit:1 sec
Input file:input.txt   Memory limit:256 Mb
Output file:output.txt  
Maximum points:100  

Statement

Young programmer Vasya tinkered with robots, and decided to create a new startup Delta Security with the goal of producing robot guardian to replace human guards.

As a first step, he considered a single wall and two patrolling robots moving back and forth along it.

First robot patrols a segment from L1 to R1 meters. Second robot patrols a segment from L2 to R2 meters.

At the start, each robot is located at the leftmost point of its segment and is facing to the right.

Each second, every robot checks whether it has reached the edge of its segment. In that case, robot reverses its direction. Then, robot moves exactly 1 meter in its current direction. Robots continue to patrol indefinitely. All robots move simultaneously.

You task is to determine maximum possible distance between two robots.

Robots could be located in the same position on the wall. This case doesn't affect their movements.

Input file format

Input file contains integers L1 R1 L2 R2.

Output file format

Output file must contain a single integer — maximum distance between robots.

Constraints

0 ≤ L1 < L2 ≤ 109, 0 ≤ R1 < R2 ≤ 109

L1 < R1, L2 < R2

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
5 10
7 12
2
2
1 5
8 9
7

0.055s 0.008s 13