Expected Fixed Points
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
2.0s
Python 3
2.0s
Memory limit:
250M
Problem type
There are people and
gifts, labelled
through
. The gifts are handed out
according to a uniformly random permutation: every permutation of the
gifts is equally
likely.
Person receives value
if they get gift
, and otherwise receives
. Let
be the total value received by everyone.
Output the expected value of .
It can be shown that the answer can be expressed as a rational number in lowest
terms with
coprime to
. Output
.
Input
The first line contains an integer .
The second line contains integers
.
Output
Print a single integer: the expected total value modulo .
Constraints
Example 1
Input
3
1 2 3
Output
2
Explanation
The expected value is .
Example 2
Input
1
7
Output
7
Explanation
There is only one permutation, so person always receives gift
.
Example 3
Input
2
5 5
Output
5
Explanation
Each person gets their own gift with probability , so the expected total is
.
Comments