Range sum queries

Answer many inclusive range-sum queries over a fixed list by precomputing prefix sums.

Easy3Prefix sumArrayInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

You are given NN numbers. Write a program that computes the sum of the ii-th number through the jj-th number.

Input

The first line contains the count of numbers NN and the number of sums to compute MM. The second line contains the NN numbers in order. Each number is a natural number no greater than 1,000. Each of the next MM lines contains the start position ii and the end position jj of one range.

Output

Print the sum of each range on its own line, in the order the ranges are given, for a total of MM lines. The sum from the ii-th number to the jj-th number includes both endpoints.

Constraints

  • 1N100,0001 \le N \le 100{,}000
  • 1M100,0001 \le M \le 100{,}000
  • 1ijN1 \le i \le j \le N