atcoder#ABC265H. [ABC265Ex] No-capture Lance Game
[ABC265Ex] No-capture Lance Game
Score : points
Problem Statement
There is a grid with horizontal rows and vertical columns, and pieces. We consider the following game using them. Two players take alternating turns. The game progresses as follows.
- In the initial state, every row contains one piece of the first player facing left and one piece of the second player facing right.
- The two players alternately advance one of their pieces.
- The player who is first to be unable to make a move loses, and the other player wins.
Let denote the square at the -th row from the top and -th column from the left. The following moves are allowed:
- The first player can move a piece at to if and none of contains a piece of either player.
- The second player can move a piece at to if and none of contains a piece of either player.
For example, in the figure below, on a grid, the first player's pieces are at , and the second player's pieces are at . The first player can move the piece at to , or , and the piece at to , or . The first player cannot move the piece at .
Currently, there is no piece on the grid. There are ways to place one piece of the first player and one piece of the second player in each row, so that no two pieces are placed at the same square. How many of them satisfy the following condition? Find the count modulo .
- When they play the game optimally from that initial state, the first player wins.
Constraints
- and are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
1 3
2
The first player can win if:
- the first player's piece is placed at , and the second player's piece is placed at ; or
- the first player's piece is placed at , and the second player's piece is placed at .
9 9
583962987
265 30
366114675