// https://w...content-available-to-author-only...f.com/CDLS23TS/problems/CDLS23H
#include "bits/stdc++.h"
using namespace std;
#ifdef DEBUG
#include "debug.h"
#else
#define see(...) ;
#endif
#define int int64_t
#define sz(x) (int)(x.size())
#define ALL(x) (x).begin(), (x).end()
#define F0R(i, R) for (int i = (0); i < (R); ++i)
#define FOR(i, L, R) for (int i = (L); i <= (R); ++i)
#include <complex>
const double PI = acos(-1);
namespace fft {
typedef complex<double> base;
void fft(vector<base>& v, bool inv) {
vector<base> w(v.size());
for (int i = 2; i <= sz(v); i <<= 1) {
int bsz = v.size() / i;
base ang(cos(2 * PI / i), sin(2 * PI / i));
if (inv)
ang = base(1, 0) / ang;
for (int j = 0; j < bsz; j++) {
for (int k = 0; k < i; k++) {
w[k] = v[bsz * k + j];
}
base pw(1, 0);
for (int k = 0; k < i / 2; k++) {
base a = w[2 * k], b = w[2 * k + 1] * pw;
v[bsz * k + j] = a + b;
v[bsz * k + j + v.size() / 2] = a - b;
pw *= ang;
}
}
}
if (inv) {
for (int i = 0; i < sz(v); i++) {
v[i] /= v.size();
}
}
}
vector<int> multiply(vector<int>& v, vector<int>& w) {
vector<base> fv(v.begin(), v.end()), fw(w.begin(), w.end());
int n = 1;
while (n < max(sz(v), sz(w)))
n <<= 1;
n <<= 1;
fv.resize(n);
fw.resize(n);
fft(fv, 0);
fft(fw, 0);
for (int i = 0; i < n; i++)
fv[i] *= fw[i];
fft(fv, 1);
vector<int> ret(n);
for (int i = 0; i < n; i++)
ret[i] = round(fv[i].real());
return ret;
}
} // namespace fft
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> pos(2 * n + 1, 0), neg(2 * n + 1, 0);
F0R(i, n) {
int val;
cin >> val;
if (val > 0) {
pos[i] = 1;
} else if (val < 0) {
neg[-i + n] = 1;
}
}
vector<int> product = fft::multiply(pos, neg);
const int MX = sz(product);
vector<int> distance_counter(MX + 1, 0);
F0R(dist, MX) {
if (product[dist] > 0) {
int d = abs(dist - n);
distance_counter[d] += product[dist];
}
}
vector<int> answer_counter(MX + 1, 0);
FOR(k, 1, MX) {
for (int multiple = k; multiple <= MX; multiple += k) {
answer_counter[k] += distance_counter[multiple];
}
}
int Q;
cin >> Q;
while (Q--) {
int K;
cin >> K;
int answer = K <= MX ? answer_counter[K] : 0;
cout << answer << " ";
}
return 0;
}
Ly8gaHR0cHM6Ly93Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5mLmNvbS9DRExTMjNUUy9wcm9ibGVtcy9DRExTMjNICgojaW5jbHVkZSAiYml0cy9zdGRjKysuaCIKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNpZmRlZiBERUJVRwojaW5jbHVkZSAiZGVidWcuaCIKI2Vsc2UKI2RlZmluZSBzZWUoLi4uKSA7CiNlbmRpZgoKI2RlZmluZSBpbnQgaW50NjRfdAojZGVmaW5lIHN6KHgpIChpbnQpKHguc2l6ZSgpKQojZGVmaW5lIEFMTCh4KSAoeCkuYmVnaW4oKSwgKHgpLmVuZCgpCiNkZWZpbmUgRjBSKGksIFIpIGZvciAoaW50IGkgPSAoMCk7IGkgPCAoUik7ICsraSkKI2RlZmluZSBGT1IoaSwgTCwgUikgZm9yIChpbnQgaSA9IChMKTsgaSA8PSAoUik7ICsraSkKCiNpbmNsdWRlIDxjb21wbGV4Pgpjb25zdCBkb3VibGUgUEkgPSBhY29zKC0xKTsKCm5hbWVzcGFjZSBmZnQgewp0eXBlZGVmIGNvbXBsZXg8ZG91YmxlPiBiYXNlOwp2b2lkIGZmdCh2ZWN0b3I8YmFzZT4mIHYsIGJvb2wgaW52KSB7Cgl2ZWN0b3I8YmFzZT4gdyh2LnNpemUoKSk7Cglmb3IgKGludCBpID0gMjsgaSA8PSBzeih2KTsgaSA8PD0gMSkgewoJCWludCBic3ogPSB2LnNpemUoKSAvIGk7CgkJYmFzZSBhbmcoY29zKDIgKiBQSSAvIGkpLCBzaW4oMiAqIFBJIC8gaSkpOw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