

Time Limit: 4 sec / Memory Limit: 1024 MB
配点 : 点
問題文
以上 以下の整数からなる長さ の数列 があります。
今からすぬけくんが以下の操作 1, 2 を順に行います。
- を満たすそれぞれの について、 以上 以下の整数を独立かつ一様ランダムに選び、 をその整数で置き換える。
- を昇順に並び替える。
すぬけくんが操作 1, 2 を行ったあとの の期待値を で出力してください。
「期待値を で出力」とは
求める期待値は必ず有理数となることが証明できます。 またこの問題の制約下では、その値を互いに素な つの整数 , を用いて と表したとき、 かつ を満たす整数 がただ つ存在することが証明できます。この を出力してください。制約
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
出力
すぬけくんが操作 1, 2 を行ったあとの の期待値を で出力せよ。
入力例 1Copy
3 5 2 2 0 4
出力例 1Copy
3
すぬけくんは操作 1 において を 以上 以下の整数で置き換えます。この整数を とすると、
- のとき、すぬけくんが操作 1, 2 を行ったあと です。
- のとき、すぬけくんが操作 1, 2 を行ったあと です。
- のとき、すぬけくんが操作 1, 2 を行ったあと です。
よって、 の期待値は です。
入力例 2Copy
2 3 1 0 0
出力例 2Copy
221832080
期待値は です。
入力例 3Copy
10 20 7 6 5 0 2 0 0 0 15 0 0
出力例 3Copy
617586310
Score : points
Problem Statement
We have a sequence of length consisting of integers between and , inclusive: .
Snuke will perform the following operations 1 and 2 in order.
- For each such that , independently choose a uniform random integer between and , inclusive, and replace with that integer.
- Sort in ascending order.
Print the expected value of after the two operations, modulo .
How to print a number modulo ?
It can be proved that the sought expected value is always rational. Additionally, under the Constraints of this problem, when that value is represented as using two coprime integers and , it can be proved that there is a unique integer such that and . Print this .Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the expected value of after the two operations, modulo .
Sample Input 1Copy
3 5 2 2 0 4
Sample Output 1Copy
3
In the operation 1, Snuke will replace with an integer between and . Let be this integer.
- If or , we will have after the two operations.
- If , we will have after the two operations.
- If or , we will have after the two operations.
Thus, the expected value of is .
Sample Input 2Copy
2 3 1 0 0
Sample Output 2Copy
221832080
The expected value is .
Sample Input 3Copy
10 20 7 6 5 0 2 0 0 0 15 0 0
Sample Output 3Copy
617586310