e-olymp
Problems

Number of permutation

Number of permutation

Given a permutationofn numbersfrom 1 to n.Findits number in thelexicographic order.

Input

The first line contains the integer n (1n12). The next line contains the permutation ofnnumbers, separatedby spaces.

Output

Print the permutation numberin lexicographical order.

Time limit 1 second
Memory limit 64 MiB
Input example
3
2 1 3
Output example
3