atcoder#ABC215G. [ABC215G] Colorful Candies 2
[ABC215G] Colorful Candies 2
Score : points
Problem Statement
There are candies arranged in a row from left to right. Each candy has one of the following colors: Color , Color , , Color . For each , the -th candy from the left has Color .
Takahashi will choose from the candies and get those candies. There are ways to choose from the candies, where is a binomial coefficient. Takahashi will randomly select one of these ways with equal probability.
Because Takahashi wants to eat colorful candies, the more variety of colors his candies have, the happier he will be. For each scenario , find the expected value of the number of different colors Takahashi's candies will have. We can prove that the sought value is a rational number. Print this rational number modulo , as described in Notes.
Notes
When you print a rational number, first write it as a fraction , where are integers and is not divisible by (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer between and , inclusive, that satisfies .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the expected value of the number of different colors Takahashi's candies will have for the scenario , modulo as described in Notes.
3
1 2 2
1
665496237
2
When , he will get the -st candy, -nd candy, or -rd candy. In any case, his candy will have one color, so the expected value of the number of different colors is .
When , he will get the -st and -nd candies, -nd and -rd candies, or -st and -rd candies.
- If he gets the -st and -nd candies, they have two different colors.
- If he gets the -nd and -rd candies, they have one color.
- If he gets the -st and -rd candies, they have two different colors.
Thus, the expected value of the number of different colors is $\frac{1}{3} \cdot 2 + \frac{1}{3} \cdot 1 + \frac{1}{3} \cdot 2 = \frac{5}{3}$. Be sure to print it modulo as described in Notes.
When , he will always get the -st, -nd, and -rd candies, which have two different colors, so the expected value of the number of different colors is .
11
3 1 4 1 5 9 2 6 5 3 5
1
725995895
532396991
768345657
786495555
937744700
574746754
48399732
707846002
907494873
7