#abc259h. [abc259_h]Yet Another Path Counting
[abc259_h]Yet Another Path Counting
Problem Statement
We have a grid of squares with rows arranged vertically and columns arranged horizontally. The square at the -th row from the top and -th column from the left has an integer label .
Consider paths obtained by starting on one of the squares and going right or down to an adjacent square zero or more times. Find the number, modulo , of such paths that start and end on squares with the same label.
Two paths are distinguished when they visit different sets of squares (including the starting and ending squares).
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2
1 3
3 1
Sample Output 1
6
The following six paths satisfy the requirements. ( denotes the square at the -th row from the top and -th column from the left. Each path is represented as a sequence of squares it visits.)
- → →
- → →