1412 Permutation Lexicographic Index
Submit solution
Points:
100
Time limit:
1.0s
Memory limit:
32M
Problem types
Allowed languages
C, C++, Java, Python
Description
A N long sequence made up of { 1,2,3, ... , N} have N! different permutations. For example , while N=3 {1,2,3}, there are 6 permutations. Sorting them by lexicographic order,they would be(1)123, (2)132,(3)213,(4)231,(5)312,(6)321. Now , give you a sequence make up of {1,2,3, ... , N}. Can you calculate its lexicographic index(1-based).
Input
Multiple cases. For each case, first line is an integer N (1<=N<=100000), secend line contains N different integers,{ A1,A2, ... An},(1<=Ai<=N).
Output
Output its lexicographic order on a single line for each case. To make this problem easy, just output the result module 9973.
Sample
Input
3
1 2 3
4
4 2 1 3
Output
1
21
Source: MoonLight
Comments