Swapping Inversions

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

You are given a permutation xx of the integers from 11 to nn.

You want to sort this permutation by a sequence of operations. In one operation, you select two adjacent elements x_ix\_i and x_i+1x\_{i+1} such that x_i>x_i+1x\_i > x\_{i+1} and swap them. When there are multiple choices of such ii, you choose one of them with equal probability. When there is no such ii, the process ends.

The cost of swapping x_ix\_i and x_i+1x\_{i+1} is x_ix_i+1|x\_i - x\_{i+1}|. Calculate the expected total cost of sorting the permutation modulo 109+710^9 + 7.

입력

The first line of input contains an integer nn (1n1061 \leq n \leq 10^6).

The second line contains nn integers x_1,x_2,,x_nx\_1, x\_2, \ldots, x\_n (1x_in1 \leq x\_i \leq n). It is guaranteed that xx is a permutation of the integers from 11 to nn.

출력

Print a single line containing an integer: the expected total cost modulo 109+710^9 + 7.

Formally, it can be shown that the expected total cost can be represented as a fraction p/qp / q for some coprime non-negative integers pp and qq. For example, if the expected total cost is an integer, then we just have q=1q = 1. You have to print the value pq1mod(109+7)p \cdot q^{-1} \bmod (10^9 + 7).