14893 - Cortisol Meter   

Description

It is the start of the semester, Tachyon and her fellow classmates are preparing for the second lab in Introduction to Programming(II).
To measure how stressful she is during the first few weeks, Tachyon recorded a daily "stress fluctuation" value for N days:

  • A positive integer indicates that her stress level went up
  • A negative integer indicates that her stress level went down

Afterward, Tachyon wants to compute her cortisol level during selected periods of time. For each of Q queries, she chooses two day a and b (both days are included), and outputs the sum of stress fluctuations over the selected period.

 

 

 

 

 

 

 

 

 

 

 

Constraints

  • 1 <= N <= 10000
  • 1 <= Q <= 100
  • 0 <= a <= b < N
  • -100 <= Ai <= 100

Input

  • The first line contains an integer N
  • The second line contains N integers, representing the "stress fluctuation" that day
  • The third line contains an integer Q
  • The next Q lines each contain two integers a b, representing the selected period of days (both inclusive)

Output

  • For each query, output a single line containing the sum of stress fluctuations from day a to day (both inclusive)
  • Output '\n' after every line

Sample Input  Download

Sample Output  Download




Discuss