atcoder#ARC129F. [ARC129F] Let's Play Tag
[ARC129F] Let's Play Tag
Score : points
Problem Statement
Snuke and children are standing on a number line.
At time , they are at the following positions.
- Snuke is at coordinate .
- children are at negative coordinates. The -th of them is at coordinate .
- children are at positive coordinates. The -th of them is at coordinate .
They will now play a game of tag. Specifically, they will do the following actions.
- Snuke first chooses a string consisting of
L
s andR
s. Then, for each , he does the following.- If the -th character of isL
, start moving at a speed of in the negative direction.- If the -th character of is
R
, start moving at a speed of in the positive direction. - When having caught a child (by occupying the same coordinate), go to the next , or end the game if .
- If the -th character of is
- If the -th character of is
L
, start moving at a speed of in the negative direction. - If the -th character of is
R
, start moving at a speed of in the positive direction. - When having caught a child (by occupying the same coordinate), go to the next , or end the game if .
- Every child keeps moving at a speed of in the direction away from Snuke.
Assume that we have found the time when the game ends for every that Snuke can choose in the beginning. Find the sum of all those values, modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 3
1 2 3
1 2 3
2748
For example, if LRRLLR
, the game goes as follows.
- At time : Snuke starts moving in the negative direction.
- At time : Snuke catches a child at coordinate and starts moving in the positive direction.
- At time : Snuke catches a child at coordinate and starts moving in the positive direction.
- At time : Snuke catches a child at coordinate and starts moving in the negative direction.
- At time : Snuke catches a child at coordinate and starts moving in the negative direction.
- At time : Snuke catches a child at coordinate and starts moving in the positive direction.
- At time : Snuke catches a child at coordinate and ends the game.
7 5
89789743 196247866 205535557 542612813 782887985 889864096 899373580
539329402 618885430 714090971 717251433 860233092
937403116