#include<iostream>
#include<cstdio>
using namespace std;
long long n,m;
long long c[500005],a;
long long x,l,r,k,z;
long long lowbit(long long x)
{
return x&(-x);
}
long long getsum(long long pos)
{
long long res=0;
while(pos>0)
{
res+=c[pos];
pos-=lowbit(pos);
}
return res;
}
void add(long long pos,long long num)
{
while(pos<=n)
{
c[pos]+=num;
pos+=lowbit(pos);
}
}
int main()
{
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
cin>>n;
for(long long i=1;i<=n;i++)
{
cin>>a;add(i,a);
}
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>l>>r;cout<<getsum(r)-getsum(l-1)<<endl;
}
fclose(stdin);fclose(stdout);
return 0;
}