#include<cstdio>
const int maxn=10005;
int n;
long long ori[maxn];
long long ta[maxn];
long long sum(int r){
if(r==0)return 0;
long long tot=0;
int tmp=r;
while(tmp){
tot+=ta[tmp];
tmp-=tmp&(-tmp);
}
tot+=ta[tmp];
return tot;
}
inline void update(long long x,int pos){
for(int i=pos;i<=n;i+=(i&(-i)))ta[i]+=x;
}
long long read(){
char ch;bool minus=false;
while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-')
if(ch=='-'){
minus=true;ch=getchar();
}
int x=ch-48;
while(ch=getchar(),ch<='9'&&ch>='0'){
x=(x<<3)+(x<<1)+ch-48;
}
return x;
}
int main(){
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
scanf("%d",&n);long long tmp;
for(int i=1;i<=n;i++){
tmp=read();
update(tmp,i);
}
scanf("%*d");
int a,b;
while(scanf("%d%d",&a,&b)!=EOF){
printf("%lld\n",sum(b)-sum(a-1));
}
fclose(stdin);fclose(stdout);
return 0;
}