#P2524. Uim的情人节礼物·其之弐

Uim的情人节礼物·其之弐

Description

Prequel: see Luogu P2525.

Uim successfully delivered gifts to NN girls in some order and maintained their harmony.

Now Uim wants to know the lexicographic rank of the final order he chose among all gift-giving orders for NN girls. The order can be viewed as a permutation of 1,2,,N1,2,\cdots,N.

Input Format

The first line contains an integer NN.

The second line contains an integer XX, representing the given permutation.

Output Format

Output a single integer, indicating its position in lexicographic order.

3
231
4

Hint

1N91\le N \le 9.

Please note that the permutation in the input has no spaces.

Translated by ChatGPT 5