Subarray minimum sum

Write codeHard30 minMeta style

Your task

Given an array of positive integers, return the sum of the minimum element over every contiguous subarray, modulo 1_000_000_007. There are n*(n+1)/2 subarrays. The array has at least one element.

Examples

sum_subarray_mins(arr: list[int]) -> int
Example 1
Inputsum_subarray_mins([3, 1, 2, 4])
Output17