fork download
  1. def prefix_sum(arr,n):
  2. prefix = [0]*(n)
  3. prefix[0] = arr[0]
  4. for i in range(1, n):
  5. prefix[i] = prefix[i-1]+arr[i]
  6. return prefix
  7.  
  8. n = int(input())
  9. arr = [int(input()) for _ in range(n)]
  10. l = int(input())
  11. r = int(input())
  12. prefix = prefix_sum(arr, n)
  13.  
  14. if l==0:
  15. print(prefix[r])
  16. else:
  17. print(prefix[r]-prefix[l-1])
  18.  
Success #stdin #stdout 0.11s 14020KB
stdin
5
2
4
6
8
10
1
3
stdout
18