Problems > Sum of Every Minimum

Sum of Every Minimum

Difficulty: 1900 5000 ms 128 MB

math stack

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.