#include<cstdio>
using namespace std;
long long where[500000],n,m;
inline long long lowbit(long long a)
{
return a&(-a);
}
void nnew (long long x,long long y)
{
while(x<=n)
{
where[x]+=y;
x+=lowbit(x);
}
}
long long sum(long long x)
{
long long summ=0;
while(x>0)
{
summ+=where[x];
x-=lowbit(x);
}
return summ;
}
int main()
{
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
scanf("%lld",&n);
long long j,k; long long z;
for(long long i=1;i<=n;i++)
{
scanf("%lld",&z);
nnew(i,z);
}
scanf("%lld",&m);
for(long long i=1;i<=m;i++)
{
scanf("%lld%lld",&j,&k);
printf("%lld\n",sum(k)-sum(j-1));
}
// while(1);
return 0;
}