atcoder#CADDI2018D. Square
Square
Score : points
Problem Statement
Takahashi has an grid. The square at the -th row and the -th column of the grid is denoted by . Particularly, the top-left square of the grid is , and the bottom-right square is .
An integer, or , is written on of the squares in the Takahashi's grid. Three integers and describe the -th of those squares with integers written on them: the integer is written on the square .
Takahashi decides to write an integer, or , on each of the remaining squares so that the condition below is satisfied. Find the number of such ways to write integers, modulo .
- For all , there are even number of s in the square region whose top-left square is and whose bottom-right square is .
Constraints
- If , then .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of possible ways to write integers, modulo .
3 3
1 1 1
3 1 0
2 3 1
8
For example, the following ways to write integers satisfy the condition:
101 111
011 111
000 011
4 5
1 3 1
2 4 0
2 3 1
4 2 1
4 4 1
32
3 5
1 3 1
3 3 0
3 1 0
2 3 1
3 2 1
0
4 8
1 1 1
1 2 0
3 2 1
1 4 0
2 1 1
1 3 0
3 4 1
4 4 1
4
100000 0
342016343