#abc234g. [abc234_g]Divide a Sequence
[abc234_g]Divide a Sequence
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.
Sample Input 1
3
1 2 3
Sample Output 1
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.
Sample Input 2
4
1 10 1 10
Sample Output 2
90
Sample Input 3
10
699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794
Sample Output 3
877646588
Be sure to print the sum modulo .