atcoder#ARC133E. [ARC133E] Cyclic Medians
[ARC133E] Cyclic Medians
Score : points
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 .
- 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.
2 1 2 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 .
2 2 5 4
2019
2100 2300 2201 2022
407723438