#include #define rep(i,a,b) for(int i=a;i P; void fft(vector

&a, int isRev = 0) { // 配列aのサイズは2の累乗じゃないとダメ const P I(0.0, 1.0); int n = a.size(); double theta = 2 * PI / n; if (isRev) theta = -2 * PI / n; for (int m = n; m >= 2; m >>= 1) { int mh = m >> 1; rep(i, 0, mh) { P w = exp(i*theta*I); for (int j = i; j < n; j += m) { int k = j + mh; P x = a[j] - a[k]; a[j] += a[k]; a[k] = w * x; } } theta *= 2; } int i = 0; rep(j, 1, n - 1) { for (int k = n >> 1; k >(i ^= k); k >>= 1); if (j < i) swap(a[i], a[j]); } if (isRev) rep(i, 0, n) a[i] /= n; } vector convolution(vector a, vector b) { int n = a.size(), m = 1; while (m < n) m *= 2; vector

A(m), B(m); rep(i, 0, n) { A[i] = P(a[i], 0); B[i] = P(b[i], 0); } fft(A); fft(B); vector

C(m); rep(i, 0, m) C[i] = A[i] * B[i]; fft(C, 1); vector res; rep(i, 0, n) res.push_back(int(real(C[i]) + 0.3)); return res; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int L, M, N, Q; //--------------------------------------------------------------------------------------------------- void _main() { cin >> L >> M >> N; vector A(N * 2 + 2), B(N * 2 + 2); int x; rep(i, 0, L) cin >> x, A[x] = 1; rep(i, 0, M) cin >> x, B[N - x] = 1; cin >> Q; auto ans = convolution(A, B); rep(i, N, N + Q) printf("%d\n", ans[i]); }