atcoder#ARC124E. [ARC124E] Pass to Next
[ARC124E] Pass to Next
Score : points
Problem Statement
people called Person are standing in a circle.
For each , Person 's neighbor to the right is Person , and Person 's neighbor to the right is Person .
Person initially has balls.
They will do the following procedure just once.
- Each person chooses some (possibly zero) of the balls they have.
- Then, each person simultaneously hands the chosen balls to the neighbor to the right.
- Now, make a sequence of length , where the -th term is the number of balls Person has at the moment.
Let be the set of all sequences that can result from the procedure. For example, when , we have $S= \{(0,1,2),(0,2,1),(1,0,2),(1,1,1),(1,2,0),(2,0,1),(2,1,0) \}$.
Compute , modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print , modulo .
3
1 1 1
1
- We have $S= \{(0,1,2),(0,2,1),(1,0,2),(1,1,1),(1,2,0),(2,0,1),(2,1,0) \}$.
- is .
3
2 1 1
6
20
5644 493 8410 8455 7843 9140 3812 2801 3725 6361 2307 1522 1177 844 654 6489 3875 3920 7832 5768
864609205
- Be sure to compute it modulo .