Gats and the Colorful Landing
Gats has built a bridge consisting of stones in a row, numbered . Each stone is assigned to one cat whose collar has color . Initially, every stone is empty.
There are rounds. In each round, one cat that has not yet arrived is chosen uniformly at random and jumps onto its assigned stone. Thus, every one of the possible arrival orders is equally likely.
Suppose the cat assigned to stone has just arrived. Consider the maximal consecutive block of occupied stones containing . A colorful trio is an unordered set of three cats at positions , , and such that
and the three collar colors , , and are pairwise distinct.
For every colorful trio in this block, Gats catches one fish. The fish are awarded anew after every arrival, so the same trio may award another fish in a later round if it belongs to the new cat's block again.
Let be the total number of fish caught after all rounds. Compute the expected value of modulo .
Input
The first line contains an integer (), the number of stones and cats.
The second line contains integers (), where is the collar color of the cat assigned to stone . Cats have the same color exactly when their integers are equal.
Output
Print one integer: the expected total number of fish, modulo .
More precisely, if the exact expectation is in lowest terms, print
Samples
Sample 1
Input
2 7 8
Output
0
A block can never contain a trio, so Gats always catches fish.
Sample 2
Input
4 1 2 3 4
Output
499122181
Among the possible arrival orders, give a total of fish and give a total of fish. The expectation is therefore , whose required representation is .