#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
int q;
cin >> q;
for(int query = 0; query < q; query++){
int l, r;
cin >> l >> r;
l--; r--;
int result = 0;
for(int first = l; first <= r; first++){
int sum = 0;
for(int last = first; last <= r; last++){
sum += a[last];
if(sum == 0){
result++;
}
}
}
cout << result << endl;
}
return 0;
}