{"raw_statement":[{"iden":"problem statement","content":"Snuke has an integer sequence $A$ whose length is $N$. He likes permutations of $(1, 2, ..., N)$, $P$, that satisfy the following condition:\n\n*   $P_i \\leq A_i$ for all $i$ ( $1 \\leq i \\leq N$ ).\n\nSnuke is interested in the inversion numbers of such permutations. Find the sum of the inversion numbers over all permutations that satisfy the condition. Since this can be extremely large, compute the sum modulo $10^9+7$."},{"iden":"notes","content":"The _inversion number_ of a sequence $Z$ whose length $N$ is the number of pairs of integers $i$ and $j$ ( $1 \\leq i < j \\leq N$ ) such that $Z_i > Z_j$."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq A_i \\leq N$ ( $1 \\leq i \\leq N$ )\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $...$ $A_N$"},{"iden":"sample input 1","content":"3\n2 3 3"},{"iden":"sample output 1","content":"4\n\nThere are four permutations that satisfy the condition: $(1,2,3)$, $(1,3,2)$, $(2,1,3)$ and $(2,3,1)$. The inversion numbers of these permutations are $0$, $1$, $1$ and $2$, respectively, for a total of $4$."},{"iden":"sample input 2","content":"6\n4 2 5 1 6 3"},{"iden":"sample output 2","content":"7\n\nOnly one permutation $(4,2,5,1,6,3)$ satisfies the condition. The inversion number of this permutation is $7$, so the answer is $7$."},{"iden":"sample input 3","content":"5\n4 4 4 4 4"},{"iden":"sample output 3","content":"0\n\nNo permutation satisfies the condition."},{"iden":"sample input 4","content":"30\n22 30 15 20 10 29 11 29 28 11 26 10 18 28 22 5 29 16 24 24 27 10 21 30 29 19 28 27 18 23"},{"iden":"sample output 4","content":"848414012"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}