atcoder#CODEFESTIVAL2017QUALBE. Popping Balls
Popping Balls
Score : points
Problem Statement
balls are arranged in a row. The leftmost balls are colored red, and the rightmost balls are colored blue.
You perform the following operation:
- First, you choose two integers such that .
- Then, you repeat the following step times: In each step, you remove the first ball or the -th ball (if it exists) or the -th ball (if it exists, all indices are 1-based) from left in the row, and give it to Snuke.
In how many ways can you give the balls to Snuke? Compute the answer modulo .
Here, we consider two ways to be different if for some , the -th ball given to Snuke has different colors. In particular, the choice of doesn't matter. Also, we don't distinguish two balls of the same color.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 3
20
There are ways to give red balls and blue balls. It turns out that all of them are possible.
Here is an example of the operation (r
stands for red, b
stands for blue):
- You choose .
- Initially, the row looks like
rrrbbb
. - You remove rd ball (
r
) and give it to Snuke. Now the row looks likerrbbb
. - You remove th ball (
b
) and give it to Snuke. Now the row looks likerrbb
. - You remove st ball (
r
) and give it to Snuke. Now the row looks likerbb
. - You remove rd ball (
b
) and give it to Snuke. Now the row looks likerb
. - You remove st ball (
r
) and give it to Snuke. Now the row looks likeb
. - You remove st ball (
b
) and give it to Snuke. Now the row is empty.
This way, Snuke receives balls in the order rbrbrb
.
4 4
67
There are ways to give red balls and blue balls.
Among them, only bbrrbrbr
, brbrbrbr
, and brrbbrbr
are impossible.
7 9
7772
1987 1789
456315553