#151Easy
Range sum
Time: 1 s · Memory: 256 MB
- Prefix sums
Statement
You are given an array of integers and queries. For every query find the sum .
Input format
The first line contains and (). The second line contains integers (). Each of the next lines contains a query: two integers and ().
Output format
For every query print one number on a separate line — the sum.
Examples
Input
8 4 3 2 4 5 1 1 5 3 2 4 5 6 1 8 3 3
Output
11 2 24 4
Note
Summing with a loop in every query is — operations. Compute the prefix sums () once; then every answer is in .
The sum reaches — a 64-bit type is needed.
Source: CSES, problem 1646.
