#P8923. 『MdOI R5』Many Minimizations
『MdOI R5』Many Minimizations
Background
This problem is not a polynomial problem. It is recommended to solve E first.
Problem Description
Little L ran into a classic problem: given an integer sequence of length , you need to choose a non-decreasing real-valued sequence as among all such sequences, to minimize . It can be proven that the answer is an integer.
He solved it instantly: isn't this just the isotonic regression template?
He felt the problem was too easy, so he decided to make it harder:
For all integer sequences of length satisfying , compute the sum of the answers to the problem above, modulo the prime . Here are given constants.
Now Little L could not do it anymore. To avoid letting you see that he actually could not do it at all, he casually wrote down some constraints and threw the problem to you.
Now the pressure is on you. Can you solve this problem successfully?
Input Format
There is one line containing three integers, representing in order.
Output Format
There is one line containing one integer, representing the answer.
3 2 1000000007
4
5 5 1000000007
11040
50 50 1000000009
875463033
Hint
For of the testdata, , , , and is guaranteed to be prime.
: .
: .
: .
: .
: .
: .
: .
: no special constraints.
Sample Explanation 1
There are the following possible cases:
.
.
.
.
.
.
.
.
Therefore the answer is .
Note that for a fixed , the optimal is not necessarily unique. Only one possible solution is shown above.
: achieve when is an NTT modulus. In fact, based on the intended solution of this problem, this part is not difficult.
Translated by ChatGPT 5
