Gats and the Flipped Garland
Gats has arranged colored beads in a line. The color of the bead at position is .
He chooses one pair of indices uniformly at random from all pairs satisfying . He then reverses the order of the beads from position through position , inclusive. Let the resulting sequence of colors be .
Each gap between adjacent positions has a different sensitivity. For every satisfying , the gap between positions and contributes tension units if , and contributes otherwise. Thus the total tension is
Find the expected total tension after Gats performs the random reversal.
Input
The first line contains an integer (), the number of beads.
The second line contains integers (), the colors of the beads in their initial order.
Output
Let , and let be the sum of the resulting tensions over all possible intervals.
Print the integer
Samples
Sample 1
Input
1 7
Output
0
There is no gap between beads, so the tension is always .
Sample 2
Input
3 1 2 2
Output
499122178
For intervals , , , , , and , the resulting tensions are , and . Their expected value is , whose required representation is .