#include <iostream>
using namespace std;
int main() {
int n,k;
cin>>n;
int a[n+1];
long long pr[n+2]={0,};
for(int i=1; i<=n; i++)
cin>>a[i];
cin>>k;
for(int i=1; i<=n; i++)
if(a[i]==0) pr[i]=pr[i-1]+1;
else pr[i]=pr[i-1];
for(int i=0; i<k; k--){
int x,y;
cin>>x>>y;
cout<<pr[y]-pr[x-1]<<endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpIHsKCWludCBuLGs7CgljaW4+Pm47CglpbnQgYVtuKzFdOwoJbG9uZyBsb25nIHByW24rMl09ezAsfTsKCWZvcihpbnQgaT0xOyBpPD1uOyBpKyspCgkJY2luPj5hW2ldOwoJY2luPj5rOwoJZm9yKGludCBpPTE7IGk8PW47IGkrKykKCQlpZihhW2ldPT0wKSBwcltpXT1wcltpLTFdKzE7CgkJZWxzZSBwcltpXT1wcltpLTFdOwoJZm9yKGludCBpPTA7IGk8azsgay0tKXsKCQlpbnQgeCx5OwoJCWNpbj4+eD4+eTsKCWNvdXQ8PHByW3ldLXByW3gtMV08PGVuZGw7Cgl9Cn0=