------
## 最终结论
```python
def sum_of_subarray_mins(A):
    MOD = 10**9 + 7
    n = len(A)
    
    # Initialize arrays to store the previous and next less elements
    prev_less = [0] * n
    next_less = [0] * n
    
    # Fill prev_less
    stack = []
    for i in range(n):
        while stack and A[stack[-1]] >= A[i]:
            stack.pop()
        prev_less[i] = stack[-1] if stack else -1
        stack.append(i)

    # Clear stack to reuse for next_less
    stack.clear()
    
    # Fill next_less
    for i in range(n - 1, -1, -1):
        while stack and A[stack[-1]] > A[i]:
            stack.pop()
        next_less[i] = stack[-1] if stack else n
        stack.append(i)

    # Calculate the sum of minimums of all subarrays
    total_sum = 0
    for i in range(n):
        left_count = i - prev_less[i]
        right_count = next_less[i] - i
        total_sum += A[i] * left_count * right_count
        total_sum %= MOD

    return total_sum

# Example usage:
print(sum_of_subarray_mins([3, 1, 2, 4]))  # Output: 17
```