var n,m,i,j,k,l,r:longint;
a,b:array[1..10001] of longint;
function lowbit(x:longint):longint;
begin
exit(x and (-x));
end;
procedure add(p,w:longint);//在p位置加w
begin
while p<= n do begin
inc(b[p],w);
inc(p,lowbit(p));
end;
end;
function sum(p:longint):longint;//求前p项和
begin
sum:=0;
while p>= 1 do begin
inc(sum,b[p]);
dec(p,lowbit(p));
end;
end;
procedure main;
begin
fillchar(a,sizeof(a),0);
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do add(i,a[i]);
{for i:=1 to n do writeln(a[i]);}
readln(m);
for i:=1 to m do
begin
readln(l,r);
writeln(sum(r)-sum(l-1));
end;
end;
begin
assign(input,'sum.in');
assign(output,'sum.out');
reset(input);
rewrite(output);
main;
close(input);
close(output);
end.