#abc249h. [abc249_h]Dye Color
[abc249_h]Dye Color
Problem Statement
There are balls numbered through . Initially, Ball is painted in Color .
Colors are represented by integers between and , inclusive.
Consider repeating the following operation until all the colors of the balls become the same.
- There are subsets (including the empty set) of the set consisting of the balls; choose one of the subsets uniformly at random. Let be the indices of the chosen balls. Next, choose a permutation obtained by choosing integers out of integers uniformly at random. Let be the chosen permutation. For each integer such that , change the color of Ball to .
Find the expected value of number of operations, modulo .
Here a permutation obtained by choosing integers out of integers is a sequence of integers between and , inclusive, whose elements are pairwise distinct.
Notes
We can prove that the sought expected value is always a rational number. Also, under the Constraints of this problem, when the value is represented by two coprime integers and as , we can prove that there exists a unique integer such that and . Find this .
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 2
Sample Output 1
4
The operation is repeated until a subset of size is chosen and the color of the ball is changed to the color of the ball not contained in the subset. The probability is $\\displaystyle \\frac{2}{4} \\times \\frac{1}{2}=\\frac{1}{4}$, so the expected value is .
Sample Input 2
3
1 1 1
Sample Output 2
0
The operation is never performed, since the colors of the balls are already the same.
Sample Input 3
10
3 1 4 1 5 9 2 6 5 3
Sample Output 3
900221128