atcoder#AGC049E. [AGC049E] Increment Decrement
[AGC049E] Increment Decrement
Score : points
Problem Statement
Maroon came up with the following problem:
Snuke has an integer sequence of length . Initially, for every ().
Snuke will repeat the following two operations any number of times in any order:
- Operation : Replace with , where () and ( or ) are integers of his choice. The cost of doing this operation once is .
- Operation : Replace with for every (), where , () and ( or ) are integers of his choice. The cost of doing this operation once is .
You are given an integer sequence of length . Snuke wants to make for every . Find the minimum total cost needed to achieve his objective.
However, during the preparation of this problem, too many unexpected solutions were found, so Maroon changed the problem into the following:
Snuke has integer sequences and integers and . The length of every sequence () is .
Now, he wants to make an integer sequence of length and find the answer to the problem above. The value of will be chosen from . Here, even if there are duplicated values in , we still distinguish those values. That is, there are ways to make .
Find the sum of the answers to the problem above over all the ways to make , modulo .
Solve this problem.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
5 2 1
2
3
1
2
1
6
We have . Below is one optimal sequence of operations:
- Let and do Operation , resulting in .
- Let and do Operation , resulting in .
- Let and do Operation , resulting in .
- Let and do Operation , resulting in .
3 2 3
1 2 3
1 2 3
1 2 3
126
10 4 1
8
10
10
1
5
9
5
5
9
1
45
10 5 10
79 48 35 56 16 26 37 6 75 23
39 99 57 100 49 90 18 9 12 91
29 97 49 86 30 94 78 63 49 22
100 27 48 91 66 14 6 20 23 84
12 60 99 75 88 95 61 58 20 46
10 11 30 38 55 94 9 52 92 75
27 22 46 85 83 88 50 63 95 91
49 59 19 37 53 27 11 26 2 91
95 36 20 76 84 41 59 95 67 66
52 60 17 11 28 57 75 69 95 24
877826779