#P334. 【例57.1】 字典序第几小

【例57.1】 字典序第几小

Description

From the nn digits starting from 11 to nn (1n91≤n≤9), a total of n!n! different permutations can be formed. Given one of these permutations, determine its lexicographical order among all permutations.

Input Format

The first line contains an integer nn.
The second line contains an integer xx, which is a permutation of the nn digits from 11 to nn.

Output Format

An integer representing the lexicographical order of the given permutation.

Sample

4
2143
8