#hhkb2020d. [hhkb2020_d]Squares
[hhkb2020_d]Squares
Problem Statement
Given are integers , , and .
We will place a white square whose side is of length on the coordinate plane so that the vertices are at , , , and .
Then, we will place a blue square whose side is of length and a red square whose side is of length so that these squares are inside the white square (including its boundary).
Here, each side of these squares must be parallel to the - or -axis.
Additionally, each vertex of red and blue squares must be at an integer point.
Find the number of ways to place red and blue squares so that they do not strictly overlap (they may share boundary with each other), modulo .
Solve this problem for test cases in each input file.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input as follows. The first line of input is in the format below:
Then, test cases follow, each of which is in the format below:
Output
For each test case, print the number of ways to place red and blue squares so that they do not strictly overlap, modulo . Use one line for each test case.
Sample Input 1
3
3 1 2
4 2 2
331895368 154715807 13941326
Sample Output 1
20
32
409369707
For example, in the first test case, there are ways to place the blue squares and ways to place the red squares, ignoring overlap.
Wherever we place the red square, there are ways to place the blue square so that it strictly overlaps with the red square.
Thus, there are ways to place red and blue squares so that they do not strictly overlap.
Note that the squares may share boundary with each other. For example, when the bottom-left vertices of blue and red squares are and , respectively, the squares do not strictly overlap.