atcoder#ABC232E. [ABC232E] Rook Path
[ABC232E] Rook Path
Score : points
Problem Statement
There is a -square grid with horizontal rows and vertical columns. Let denote the square at the -th row from the top and -th column from the left.
The grid has a rook, initially on . Takahashi will do the following operation times.
- Move the rook to a square that shares the row or column with the square currently occupied by the rook. Here, it must move to a square different from the current one.
How many ways are there to do the operations so that the rook will be on in the end? Since the answer can be enormous, find it modulo .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the number of ways to do the operations so that the rook will be on in the end, modulo .
2 2 2
1 2 2 1
2
We have the following two ways.
- First, move the rook from to . Second, move it from to .
- First, move the rook from to . Second, move it from to .
1000000000 1000000000 1000000
1000000000 1000000000 1000000000 1000000000
24922282
Be sure to find the count modulo .
3 3 3
1 3 3 3
9