Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/65536 K (Java/Others)

Tom has learned how to calculate the number of inversions in a permutation of n distinct objects by coding, his teacher gives him a problem:

Give you a permutation of n distinct integer from 1 to n, there are many permutations of 1-n is smaller than the given permutation on dictionary order, and for each of them, you can calculate the number of inversions by coding. You need to find out sum total of them.

Tom doesn't know how to do, he wants you to help him.

Because the number may be very large, output the answer to the problem modulo ${10}^{9}+7$.

Give you a permutation of n distinct integer from 1 to n, there are many permutations of 1-n is smaller than the given permutation on dictionary order, and for each of them, you can calculate the number of inversions by coding. You need to find out sum total of them.

Tom doesn't know how to do, he wants you to help him.

Because the number may be very large, output the answer to the problem modulo ${10}^{9}+7$.

提交代码