Parquet
Time limit1sMemory limit128 MB
A brick-like tiling of the plane shifts by half a tile on every other row; count the tiles touching the border of an axis-aligned rectangle.
- Level
Medium7 of 10
- Topics
- Math, Implementation, Geometry, Brute force
- Solved
- No attempts yet
Problem
Mirko's parquet floor is made of square tiles laid in the following pattern.

The picture shows only part of the floor in an imaginary coordinate system. The floor is so large that you may assume it covers the whole plane.
Precisely, the pattern is as follows. For every integer , the line is a tile boundary. In the row , if is even, the tiles are , and if is odd, the tiles are , for every integer .
For his mathematics thesis, Mirko drew a rectangle on the floor with red paint. Later he found out that the paint contains a harmful chemical that destroys the parquet. Now he has to replace every tile that shares at least one point with the border of the drawn rectangle. Help Mirko: how many such tiles are there?
Input
The first line contains real numbers and , the coordinates of the lower left corner of the rectangle.
The second line contains real numbers and , the coordinates of the upper right corner of the rectangle. The sides of the rectangle are parallel to the coordinate axes.
Every coordinate has at most one digit after the decimal point, and , .
Output
Print the number of tiles that must be replaced on a single line.
Hint

The picture shows the rectangle of the first example (red) and the 22 tiles that must be replaced (gray).