atcoder#ABC242F. [ABC242F] Black and White Rooks
[ABC242F] Black and White Rooks
Score : points
Problem Statement
Consider placing black rooks and white rooks on a grid with horizontal rows and vertical columns.
A placement of the rooks satisfying all of the following conditions is called a good placement.
- All rooks are placed on the grid.
- At most one rook is placed in the same square.
- There is no pair of white rook and black rook attacking each other. That is, there is no pair of white rook and black rook such that one of them can reach the square in which the other is placed in one move.
Here, in one move, a rook can reach any square that is on a horizontal or vertical line from its current position and is reachable without jumping over another rook.
How many good placements are there? Since this count can be enormous, print it modulo .
Rooks in the same color are not distinguished.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the count modulo .
2 2 1 1
4
There are four good placements as follows.
1 2 1 1
0
There may be no good placement.
40 40 30 30
467620384
Be sure to print the count modulo .