```
class Solution(object):
def countRangeSum(self, nums, lower, upper):
"""
:type nums: List[int]
:type lower: int
:type upper: int
:rtype: int
"""
res, cur_sum, sum_list = 0, 0, [0, float("inf")]
for n in nums:
cur_sum += n
res += bisect.bisect_right(sum_list, cur_sum-lower) - bisect.bisect_left(sum_list, cur_sum-upper)
bisect.insort(sum_list, cur_sum)
return res
```