------
## 最终结论
```python
def range_sum(nums, n, left, right):
    # Step 1: Generate all subarray sums
    subarray_sums = []
    for i in range(n):
        current_sum = 0
        for j in range(i, n):
            current_sum += nums[j]
            subarray_sums.append(current_sum)
    
    # Step 2: Sort the subarray sums
    subarray_sums.sort()
    
    # Step 3: Calculate the sum from index left to right (1-indexed) and apply modulo
    mod = 10**9 + 7
    result = sum(subarray_sums[left-1:right]) % mod
    
    return result

# Example usage:
print(range_sum([1,2,3,4], 4, 1, 5))  # Output: 13
print(range_sum([1,2,3,4], 4, 3, 4))  # Output: 6
print(range_sum([1,2,3,4], 4, 1, 10)) # Output: 50
```