Christmas gift P74421


Statement
 

pdf   zip

It is December 24th evening. An absent minded farmer has just realized that he did not buy any gift for his wife. The farmer is on a path in the woods, and he can only think about picking up all the mushrooms on the way back home, praying that that will soften a bit the cries awaiting him. Suppose the path divided into nn segments 1, 2, …nn, and that in each one there are a certain number of mushrooms mim_i. The farmer is at the segment ff, and his home is at the segment hh. The farmer will pick up all the mushrooms in the segments between ff and hh. How many mushrooms will it be?

Input

Input consists of several cases. Every case begins with nn, followed by the nn quantities of mushrooms mim_i. Follow the number of queries qq about this case, assuming different positions of the farmer and his home. Each query consists of ff and hh, both between 1 and nn. Suppose 1n1051 \le n \le 10^5, 0mi10000 \le m_i \le 1000, and q>0q > 0.

Output

For every case, print its number. For every query of every case, print the sum of the numbers between ff and hh, the extrems inclusive.

Public test cases
  • Input

    4   7 0 20 105
    3
    1 4
    3 3
    4 3
    1   1000
    1
    1 1
    

    Output

    #1
    132
    20
    125
    #2
    1000
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python