Олимпиадный тренинг

Задача 34771. Tile


Задача

Темы:
The wall is covered with square tiles with a side of M cm. A picture was hung on the wall, the coordinates of the lower left corner of the picture, its width and height are known. Determine the number of tiles that are partially or completely covered by the painting.

The first line of the input contains the number M – side of the tile. The second and third lines contain the numbers X and Y – coordinates of the lower left corner of the picture. The fourth and fifth lines contain the numbers W and H – the width and height of the picture. The OX axis is directed to the right, the OY axis is directed upward. The bottom left corner of one of the tiles is at the origin. All numbers are integers not exceeding 2×109 , numbers M, W, H – positive numbers X and Y – positive or equal to 0.

The program should output a single number – the number of tiles completely or partially covered by the painting. A tile is considered a closed painting if the intersection of the painting and the tile has a non-zero area, i.e. the touch between the painting and the tile is not considered an overlap.

 
Input Output Note
10
15
5
35
20
12 The example matches the picture. The side of the tile (the side of the cell in the figure) M = 10. The lower left corner of the picture has coordinates (15, 5), the picture has a width of 35 cm and a height of 20 cm. The picture completely or partially covers 12 tiles.