Codeforces Round 232 (Div. 1)
D
On Sum of Number of Inversions in Permutations
Codeforces
未评级
原题
← CE →
翻译中…

You are given a permutation $*p*$. Calculate the total number of inversions in all permutations that lexicographically do not exceed the given one.

翻译中…

As this number can be very large, print it modulo $1000000007$ $(10^{9} + 7)$.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 10^{6}$) — the length of the permutation. The second line contains $*n*$ distinct integers $*p*_{1}, *p*_{2}, ..., *p*_{*n*}$ ($1 ≤ *p*_{*i*} ≤ *n*$).

翻译中…

Output

翻译中…

Print a single number — the answer to the problem modulo $1000000007$ $(10^{9} + 7)$.

翻译中…

Note

翻译中…

Permutation $*p*$ of length $*n*$ is the sequence that consists of $*n*$ distinct integers, each of them is from $1$ to $*n*$.

翻译中…

An inversion of permutation $*p*_{1}, *p*_{2}, ..., *p*_{*n*}$ is a pair of indexes $(*i*, *j*)$, such that $*i* < *j*$ and $*p*_{*i*} > *p*_{*j*}$.

翻译中…

Permutation $*a*$ do not exceed permutation $*b*$ lexicographically, if either $*a* = *b*$ or there exists such number $*i*$, for which the following logical condition fulfills: image AND $(*a*_{*i*} < *b*_{*i*})$.

翻译中…

样例

Input #1
2
2 1
Output #1
1
InputCopy OutputCopy
Input #2
3
2 1 3
Output #2
2
InputCopy OutputCopy
题目信息
题号
396D
时间限制
3 s
内存限制
256 MB
标签
组合数学
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。