atcoder#ARC146F. [ARC146F] Simple Solitaire
[ARC146F] Simple Solitaire
Score : points
Problem Statement
The following process is carried out on a permutation of .
We have cards, numbered to . Card has the integer written on it.
There are an integer and a boy called PCT, who initially has nothing. PCT does the following procedure for each in this order.
- Get Card . Then, repeat the following action as long as he has a card with written on it:
- eat the card with written on it, and then add to .
- If PCT currently has or more cards, throw away all cards he has and terminate the process, without performing any more procedures.
Here, let us define the score of the permutation as follows:
- if the process is terminated by throwing away cards, the score of is ;
- if the process is carried out through the end without throwing away cards, the score of is the number of cards PCT has at the end of the -th procedure .
There are permutations of . Find the sum of the scores of all those permutations, modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 2
1
For , the process goes as follows.
- The first procedure:- PCT gets Card .
- PCT currently has card, so he goes on.
- PCT gets Card .
- PCT currently has card, so he goes on.
- The second procedure:- PCT gets Card .
- PCT eats Card and make .
- PCT currently has card, so he goes on.
- PCT gets Card .
- PCT eats Card and make .
- PCT currently has card, so he goes on.
- The third procedure:- PCT gets Card .
- PCT eats Cards and make .
- PCT currently has cards, so he goes on.
- PCT gets Card .
- PCT eats Cards and make .
- PCT currently has cards, so he goes on.
The process is carried out through the end, so the score of is .
Other than , there is no permutation with a score of or greater, so the answer is .
3 3
5
146146 146
103537573