We have a sufficiently large -dimensional grid of cells. The grid is paved with square cells from the top to the bottom and from the left to the right.
There is a cell, which is the origin of the coordinates. Let denote the cell one arrives at when one moves from the origin to the right direction for the distance of cells and to the upward direction for the distance of cells. Here, the left direction for the distance of a cells means the right direction for the distance of cells. Similarly, the downward direction for the distance of a cells means the upward direction for the distance of cells.
At time , the cells are black, and all of the other cells are white. For , the colors of the cells at time are determined by the colors of the cells at time in the following way.
- If a cell is black at time , then the cell becomes gray at time .
- If a cell is gray at time , then the cell becomes white at time .
- A cell which is white at time becomes black at time if at least one of the adjacent cells (i.e. the cells which share the edges) is black at time . Otherwise, it remains white at time . You have queries. For the -th () query, you should answer the number of black cells at time .
Write a program which, given the information of the colors of the cells at time and queries, answers the queries.
Input Specification
Read the following data from the standard input.
Output Specification
Write lines to the standard output. The -th line should contain the number of black cells at time .
Input Constraints
- .
- .
- ().
- ().
- ().
- ().
- ().
- Given values are all integers.
Subtasks
- (4 points) (), (), ().
- (12 points) (), (), ().
- (8 points) (), .
- (8 points) ().
- (17 points) , .
- (25 points) .
- (26 points) No additional constraints.
Sample Input 1
2 3
0 2
1 0
0
1
2
Sample Output 1
2
8
12
Explanation for Sample 1
The following figure shows the colors of the cells at time . Since there are black cells, the answer to the first query is .
The following figure shows the colors of the cells at time . Since there are black cells, the answer to the second query is .
The following figure shows the colors of the cells at time . Since there are black cells, the answer to the third query is .
This sample input satisfies the constraints of Subtasks .
Sample Input 2
3 5
0 0
2 2
5 5
0
1
2
3
4
Sample Output 2
3
12
21
24
26
Explanation for Sample 2
This sample input satisfies the constraints of Subtasks .
Sample Input 3
4 10
-3 -3
3 3
-4 4
4 -4
0
1
2
3
4
5
6
7
8
9
Sample Output 3
4
16
32
48
56
56
55
56
60
64
Explanation for Sample 3
This sample input satisfies the constraints of Subtasks
Comments