include
include
using namespace std; int binarySearch(int left , int right , int a[] , int n) { int c = 0; for(int i = left; i<=right ; i++) { int l = -1; int r = n; while(r>l+1) { int mid = (l+r)/2; if(a[mid] >= i) { r = mid; //cout<<a[r]<<"\n"; }
else l = mid; } if(r<n && a[r] == i) { ++c; if(count(a , a + n , i) > 1) c = c+(count(a , a + n , i)-1); } } return c;
}
int main() { int n ; cin>>n; int a[n]; for(int i = 0 ; i<n;i++) cin>>a[i]; int k; cin>>k; sort(a , a+n); for(int i = 0 ; i<k;i++) { int l , r; cin>>l>>r; cout<<binarySearch(l , r , a , n)<<"\n"; }
return 0;
}