#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

inline int tabs(int x)
{
	return x < 0 ? -x : x;
}

int N, K;

const int MOD = 51361;
vector<pair<int, int> > Hash[MOD];

void Add(int val)
{
	int where = tabs(val) % MOD;
	
	for (vector<pair<int, int> >::iterator it = Hash[where].begin(); it != Hash[where].end(); ++it)
		if (it->first == val)
		{
			++it->second;
			return;
		}
		
	Hash[where].push_back(make_pair(val, 1));
}
int Search(int val)
{
	int where = tabs(val) % MOD;
	
	for (vector<pair<int, int> >::iterator it = Hash[where].begin(); it != Hash[where].end(); ++it)
		if (it->first == val)
			return it->second;
	return 0;
}

int main()
{
	ifstream fin("punctfix.in");
	ofstream fout("punctfix.out");
	
	fin >> N;
	
	for (int i = 1, what; i <= N; ++i)
	{
		fin >> what;
		what = i - what;
		Add(what);
	}
	
	fin >> K;
	
	for (int i = 1, aux, result; i <= K; ++i)
	{
		fin >> aux;
		result = Search(aux);
		fout << result << '\n';
	}
	
	fin.close();
	fout.close();
}
