atcoder#ABC234G. [ABC234G] Divide a Sequence
[ABC234G] Divide a Sequence
Score : points
Problem Statement
Given is a sequence of numbers.
There are ways to divide into non-empty contiguous subsequences . Find the value below for each of those ways, and print the sum, modulo , of those values.
Here, for a sequence , and are defined to be the maximum and minimum values of an element of , respectively.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum, modulo , of the values found.
3
1 2 3
2
There are ways to divide into non-empty contiguous subsequences, as follows.
- , ,
- ,
- ,
for these divisions are , , , , respectively. The sum of them, , should be printed.
4
1 10 1 10
90
10
699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794
877646588
Be sure to print the sum modulo .