배열 A와 1부터 N까지의 균등 무작위 순열 P가 주어질 때, P가 정하는 위치를 반복해서 0으로 만든 뒤 배열 합의 기댓값을 1e9+7로 나눈 값을 구합니다.
어려움8수학조합론확률정수론아직 제출이 없습니다시간 제한1초메모리 제한512 MBYou have an array of N integers A = [A1, A2, · · · , AN]. Summing all integers in A is boring, so you decided to take it to the next level. You have a permutation P of 1 to N generated randomly. Each permutation from 1 to N has an equal probability to be chosen as P.
You also want to define arrays X0, X1, X2, ..., XN and an integer Y as follows:
For example, if A = [4, 1, 2, 3, 4] and P = [3, 2, 4, 1, 5], then:
Therefore, Y = 12 + 8 + 8 + 0 + 0 = 28 in this case.
Since P is generated randomly, you are wondering the expected value of Y . Let C/D be the expected value of Y where C and D are relatively prime non-negative integers. Print the value of (C ×D−1) mod 1000000007. In other words, you must print the value of the unique integer K (0 ≤ K < 1000000007) satisfying C ≡ DK (mod 1000000007).
Input begins with an integer N (1 ≤ N ≤ 100000) representing the number of integers in A. The second line contains N integers: Ai (0 ≤ Ai ≤ 109) representing the array A.
Output in a line the expected value of Y using the format specified in the problem description.