#codefestival2016qualCe. [codefestival_2016_qualC_e]Encyclopedia of Permutations
[codefestival_2016_qualC_e]Encyclopedia of Permutations
Problem Statement
One day Mr. Takahashi picked up a dictionary containing all of the ! permutations of integers through . The dictionary has ! pages, and page () contains the -th permutation in the lexicographical order.
Mr. Takahashi wanted to look up a certain permutation of length in this dictionary, but he forgot some part of it.
His memory of the permutation is described by a sequence . If , it means that he forgot the -th element of the permutation; otherwise, it means that he remembered the -th element of the permutation and it is .
He decided to look up all the possible permutations in the dictionary. Compute the sum of the page numbers of the pages he has to check, modulo .
Constraints
- if (), and .
Partial Score
- In test cases worth points, .
Input
The input is given from Standard Input in the following format:
Output
Print the sum of the page numbers of the pages he has to check, as modulo .
Sample Input 1
4
0 2 3 0
Sample Output 1
23
The possible permutations are [, , , ] and [, , , ]. Since the former is on page and the latter is on page , the answer is .
Sample Input 2
3
0 0 0
Sample Output 2
21
Since all permutations of length are possible, the answer is .
Sample Input 3
5
1 2 3 5 4
Sample Output 3
2
Mr. Takahashi remembered all the elements of the permutation.
Sample Input 4
1
0
Sample Output 4
1
The dictionary consists of one page.
Sample Input 5
10
0 3 0 0 1 0 4 0 0 0
Sample Output 5
953330050