fork download
  1. # your code goes here
  2. n=int(input())
  3. a=list(map(int, input().split()))
  4. p=[0]*n
  5. p[0]=a[0]
  6. for i in range(1, n):
  7. p[i]=p[i-1]+a[i]
  8. Q=int(input())
  9. for _ in range(Q):
  10. l, r=map(int, input().split())
  11. if l==0:
  12. total=p[r]
  13. else:
  14. total=p[r]-p[l-1]
  15. print(total)
Success #stdin #stdout 0.07s 14104KB
stdin
5
10 20 30 40 50
4
0 2
1 4
2 2
3 4
stdout
60
140
30
90