#arc163f. [arc163_f]Many Increasing Problems
[arc163_f]Many Increasing Problems
Problem Statement
PCT-kun created the following problem.
Increasing Problem
You are given a length- sequence of non-negative integers . You can perform the following operation any number of times (possibly zero).
- Choose an integer such that , and increase or decrease by .
Your goal is to make non-decreasing. Find the minimum number of operations required to achieve this goal.
Thinking that this problem is too easy to be placed at the end of the contest, PCT-kun has revised it as follows.
Many Increasing Problems
There are integer sequences of length where all elements are between and , inclusive. Find the sum of the answers to Increasing Problem for all those sequences, modulo .
Solve Many Increasing Problems.
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the answer to Many Increasing Problems.
Sample Input 1
2 2
Sample Output 1
1
Let us solve Increasing Problem for all sequences of length where all elements are between and , inclusive.
- For , the answer is .
- For , the answer is .
- For , the answer is .
- For , the answer is .
Therefore, the final answer is .
Sample Input 2
6 4
Sample Output 2
14668
Sample Input 3
163 702
Sample Output 3
20728656
Sample Input 4
98765 99887
Sample Output 4
103564942