Sum of Every Minimum
Sum the MINIMUM of every contiguous subarray, modulo 109+7.
Input: the first line has N; the second line has N positive integers.
Output: the total of all subarray minimums, mod 109+7.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ ai ≤ 109
Sample Tests
Input 1
3 3 1 2
Output 1
9
Input 2
2 5 5
Output 2
15
Discussion (opens after you solve — no spoilers before)
No comments yet.