def sum_subarray_minimums(nums):
    n = len(nums)
    previous, following = [-1] * n, [n] * n
    stack = []
    for i in range(n):
        while stack and nums[stack[-1]] >= nums[i]:
            stack.pop()
        previous[i] = stack[-1] if stack else -1
        stack.append(i)
    stack = []
    for i in range(n - 1, -1, -1):
        while stack and nums[stack[-1]] > nums[i]:
            stack.pop()
        following[i] = stack[-1] if stack else n
        stack.append(i)
    return sum(value * (i - previous[i]) * (following[i] - i)
               for i, value in enumerate(nums))
