#arc133e. [arc133_e]Cyclic Medians
[arc133_e]Cyclic Medians
Problem Statement
Given are integers , , , and . Consider the following procedure.
- Choose a sequence of integers between and (inclusive): .
- Choose a sequence of integers between and (inclusive): .
- Let be a variable and initialize it with .
- For each , do the following.
- Replace the value of with the median of .
- Print the final value of .
Consider doing this procedure with every possible pair of sequences . Find the sum of the values that will be printed, modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2 1 2 1
Sample Output 1
11
For example, when , the procedure goes as follows.
- Initialize with .
- For : replace the value of with the median of , which is .
- For : replace the value of with the median of , which is .
- Print .
There are three cases where will be printed: , , . In the other five cases, will be printed. Therefore, the answer is .
Sample Input 2
2 2 5 4
Sample Output 2
2019
Sample Input 3
2100 2300 2201 2022
Sample Output 3
407723438