Gomory, Hu și pietricelele colorate

Time limit: 1s Memory limit: 64MB Input: Output:

Gomory and Hu found nn pebbles near the lake. They noticed that they are very colorful. They want to arrange them in a sequence ... with their eyes closedwith\ their\ eyes\ closed. Due to the large number of possible arrangements, they ask for your help in computing the average number of maximal sequences of stones of the same color resulting from an arrangement, considering all possible arrangements to be equally likely.

Task

Formally, you are given an array CC of length nn with elements between 11 and nn. You must compute the average number of maximal sequences with equal values for a random permutation of the array modulo 109+710^9 + 7.

Input Data

On the first line, a natural number nn is read, representing the length of the array.

On the second line, nn natural numbers separated by spaces are read, representing the elements of the array CC.

Output Data

On the first line you must output a single natural number representing the average number of maximal contiguous sequences with equal elements of a permutation of the array CC. It can be shown that the answer can be written as an irreducible fraction ab\frac{a}{b}, where aa and bb are natural numbers and b≢0(mod109+7)b \not\equiv 0 \pmod{10^9 + 7}. You must output ab1a\cdot b^{-1} modulo 109+710^9 + 7.

Constraints

  • 1n1061 \le n \le 10^6
  • 1Cin1 \le C_i \le n
  • A sequence is obtained from an array by removing a number of elements from the beginning of the array (possibly zero) and a number of elements from the end of the array (possibly zero).
  • A maximal sequence with equal elements is a sequence of equal elements that can no longer be extended to the right or to the left while still being made up of the same element.
  • Two permutations are considered different if they differ in at least one position. For example, the array [1,2,2][1 , 2 , 2] has only 33 permutations: [1,2,2][1 , 2 , 2], [2,1,2][2 , 1 , 2], [2,2,1][2 , 2 , 1].
# Points Restrictions
1 10 n10n \le 10
2 20 There are at most two distinct values
3 50 n5000n \le 5\,000
4 20 No additional constraints

Example 1

stdin

2
1 2

stdout

2

Explanation

The permutations of the array are: [1,2][1 , 2] and [2,1][2 , 1]. Each of them has 22 maximal contiguous sequences with equal values. Therefore, the average value is 22.

Example 2

stdin

3
2 1 2

stdout

333333338

Explanation

The permutations of the array are: [1,2,2][1 , 2 , 2], [2,1,2][2 , 1 , 2] and [2,2,1][2 , 2 , 1]. These have 22, 33, and respectively 22 maximal sequences with equal elements. The average number of maximal sequences with equal elements is 2+3+23 = 73 = 333333338 (modulo 109+7)\frac{2 + 3 + 2}{3}\ =\ \frac{7}{3}\ =\ 333333338\ (modulo\ 10^9+7).

Log in or sign up to be able to send submissions!