Time limit: 1s
Memory limit: 256MB
Input:
Output:
There is a chess board of rows and columns.
There are cells that are occupied by chess pieces, and all other cells are empty.
You don't know what exact pieces occupy them, but you know that each piece is either a rook or a bishop.
You also know that no rook attacks a bishop, and no bishop attacks a rook.
Task
How many valid arrangements of pieces exist? Since this number might be too big, output it modulo .
Two arrangements are considered different if there is at least one cell which is occupied by a different piece.
Input data
The input consists of:
- a line containing integers , , .
- lines, the -th of which consisting of integers , , which mean that the cell at the -th row and -th column is occupied.
Output data
The output must contain a single line consisting of integer , the number of piece arrangements modulo , such that no rook attacks a bishop and no bishop attacks a rook.
Constraints and clarifications
- , for each
- Each cell is occupied by at most one piece (in other words, either or for ).
# | Points | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 11 | and |
3 | 19 | |
4 | 19 | |
5 | 51 | No additional constraints |
Example 1
stdin
4 2 2
1 1
3 2
stdout
4
Example 2
stdin
3 3 3
2 1
3 3
1 1
stdout
2