'''

class Solution(object):

def countRangeSum(self, nums, lower, upper):

"""

:type nums: List[int]

:type lower: int

:type upper: int

:rtype: int

"""

n = len(nums)

sumR = [0]*(n+1)

for i in range(n-1,-1,-1):

sumR[i] = sumR[i+1]+nums[i]

l = []

res = 0

for i in range(n):

bisect.insort(l,sumR[i])

x = bisect.bisect_left(l,lower+sumR[i+1])

y = bisect.bisect_right(l,upper+sumR[i+1])

res+= y-x

return res

'''