Problem
Consider a square grid of size . There are distinct directed light sources placed at the vertices of the grid. In the diagram below, the light sources are marked in dark color.
Flat mirrors of one face can be placed at the vertices of the grid not occupied by light sources, at a -degree angle with respect to the sides of the grid. These mirrors change the direction of the emitted light by degrees. A possible arrangement of mirrors and a path that the light can follow inside the grid, if the sources are properly oriented, is shown in the diagram below.
Light beams cannot pass through mirrors or light sources, and they cannot intersect.
Task
Write a program that calculates the maximum number of light beams that can exit the grid.
Input Data
The program reads the data from the file escape.in. The first line of the file contains two numbers, and . The next lines contain the coordinates and of a light source. For each , it holds and .
Example of Input:
6 10
1 3
2 2
2 3
2 4
4 2
4 3
4 4
6 2
6 3
6 4
This corresponds to the above grid.
Output Data
The result should be a text file named escape.out. It should contain only one line with the requested maximum number of light beams.
Example of Output:
10
The same output should result if we add another light source at coordinates to the above grid.
Constraints
Your program will run for at most sec.
Comments