Gomory and Hu found pebbles near the lake. They noticed that they are very colorful. They want to arrange them in a sequence ... . 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 of length with elements between and . You must compute the average number of maximal sequences with equal values for a random permutation of the array modulo .
Input Data
On the first line, a natural number is read, representing the length of the array.
On the second line, natural numbers separated by spaces are read, representing the elements of the array .
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 . It can be shown that the answer can be written as an irreducible fraction , where and are natural numbers and . You must output modulo .
Constraints
- 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 has only permutations: , , .
| # | Points | Restrictions |
|---|---|---|
| 1 | 10 | |
| 2 | 20 | There are at most two distinct values |
| 3 | 50 | |
| 4 | 20 | No additional constraints |
Example 1
stdin
2
1 2
stdout
2
Explanation
The permutations of the array are: and . Each of them has maximal contiguous sequences with equal values. Therefore, the average value is .
Example 2
stdin
3
2 1 2
stdout
333333338
Explanation
The permutations of the array are: , and . These have , , and respectively maximal sequences with equal elements. The average number of maximal sequences with equal elements is .