Collar-Gap Jumps
A long string has equally spaced seats, numbered from left to right. Initially, one cat sits at each seat. The cat at seat wears a collar of color .
The cats jump away one at a time in a uniformly random order. Equivalently, each of the possible jump orders is equally likely.
Suppose the cat originally at seat is about to jump. Let be the seat of the nearest cat that has not yet jumped and lies to its left, and let be the corresponding nearest remaining cat to its right. Either neighbor might not exist.
The jumping cat earns points if all of the following conditions hold:
- both and exist;
- ;
When these conditions hold, the cat earns
points. Otherwise, it earns points. The cat then leaves its seat permanently.
Let be the total score earned by all cats. Determine modulo .
Input
The first line contains an integer (), the number of cats.
The second line contains integers (), where is the collar color identifier of the cat initially at seat .
Output
Print one integer: the expected total score modulo .
More precisely, if in lowest terms, print
Samples
Sample 1
Input
3 1 2 1
Output
332748118
The expected total score is , whose required residue is .
Sample 2
Input
5 1 2 1 2 1
Output
598946613
For these five cats, the expected total score is , represented modulo as .