시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 8 | 8 | 8 | 100.000% |
Charles the Cryptographer has been researching novel methods of generating random numbers. In particular, by combining multiple sources of random numbers, he hopes to create a cryptographically secure pseudorandom number generator (CSPRNG).
One algorithm that he has recently invented is as follows:
The lexicographical order of P is defined as the number of permutations of S that are lexicographically smaller than3 or equal to P.
Unfortunately, Charles is a Cryptographer and not a Coder. Given the resultant permutation P, help Charles to find its lexicographical order, modulo 1 000 000 007.
1A permutation P of a sequence S is a rearrangement of the elements of S
2The remainder when the value is divided by 1 000 000 007
3A permutation P1, . . . , PN is considered lexicographically smaller than another permutation P'1 , . . . , P'N if there exists 1 ≤ k ≤ N such that Pk < P'k and Pi = P'i for i = 1, . . . , k − 1.
Your program must read from standard input.
The first line contains a single integer N.
The second line contains N space-separated integers, P1, . . . , PN.
Your program must print to standard output. The output should contain a single integer on a single line, the lexicographical order of P, modulo 1 000 000 007.
3 42 100 1
4
We have the following 6 permutations in lexicographical order:
Hence, the lexicographical order of [42, 100, 1] is 4.
5 1 5 2 4 3
20
2 2 1
2