#include #include #include using namespace std; #include struct FFT { using Complex = complex; const double PI = acos(-1); const int sz = 1 << 18; // 262144 void dft(vector &x, bool inv) { for (int i = sz >> 1; i >= 1; i >>= 1) { Complex bs = polar(1.0, 2.0 * PI * i / sz * (inv ? -1 : 1)), w = 1; vector y(sz); for (int j = 0; 2 * j < sz; j += i) { for (int k = 0; k < i; k++) { y[j + k] = x[2 * j + k] + w * x[2 * j + i + k]; y[j + k + (sz >> 1)] = x[2 * j + k] - w * x[2 * j + i + k]; } w *= bs; } x = y; } if (inv) for (int i = 0; i < sz; i++) x[i] /= sz; } vector multiply(vector &a, vector &b) { vector x(sz), y(sz); for (int i = 0; i < (int)a.size(); i++) x[i] = Complex(a[i], 0.0); for (int i = 0; i < (int)b.size(); i++) y[i] = Complex(b[i], 0.0); dft(x, false), dft(y, false); for (int i = 0; i < sz; i++) x[i] *= y[i]; dft(x, true); vector c(sz); for (int i = 0; i < sz; i++) c[i] = (long long)(x[i].real() + 0.5); return c; } } fft; int main() { int L, M, N; cin >> L >> M >> N; vector as(N), bs(N); for (int i = 0; i < L; i++) { int a; cin >> a; as[a - 1] = 1; } for (int i = 0; i < M; i++) { int b; cin >> b; bs[N - b] = 1; } auto cs = fft.multiply(as, bs); int q; cin >> q; for (int i = 0; i < q; i++) { cout << cs[N - 1 + i] << endl; } return 0; }