#P6555. Forget You
Forget You
Description
To help おとさか ゆう recover his memories, ともり なお found PZY.
After research, PZY found that abilities are mainly determined by the ability genes in the body. He labeled a total of ability genes as to , and then divided them in order into sets. The -th set contains ability genes with indices from to .
After many experiments, PZY found that the ordering of genes can be simplified into a sequence. As required, he defines a sequence to be a gene sample if and only if the sequence consists only of numbers from to . For numbers that belong to the -th set, they must be non-strictly increasing within the sequence, and each number appears in the sequence no more than times.
In particular, the research value of a gene sample is the sum of all numbers that make up the gene sample. Note that repeated numbers should also be counted repeatedly.
To help おotasaка ゆう recover his memories, PZY wants to know the sum of the research values of all gene samples.
Since the answer is very large, he only wants the remainder after dividing the answer by .
Input Format
The first line contains a positive integer .
Lines to each contain two positive integers , with the meaning as described in the statement.
Output Format
Output the remainder of the sum of the research values of all gene samples divided by .
2
2 2
1 2
300
3
2 2
3 6
2 4
661677771
Hint
Explanation of Sample 1:
The two sets are and .
For gene samples of length , we have: .
The total value is .
For gene samples of length , we have: .
The total value is .
The sequence does not satisfy the requirement that numbers in set are non-strictly increasing in the sequence.
For gene samples of length , we have: $113, 123, 131, 132, 133, 223, 232, 233, 311, 312, 313, 322, 323, 331, 332$.
The total value is .
The sequences exceed the occurrence limit.
For gene samples of length , the total value is .
So the total value is .
Let .
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号