#line 1 "compro_library/template/template.cpp" #include using namespace std; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } #define DEBUG #ifdef DEBUG template ostream &operator<<(ostream &os, const pair &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template ostream &operator<<(ostream &os, const vector &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define FOR(i, a, b) for(int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- #line 1 "compro_library/math/fft.hpp" namespace FFT { using D = double; struct C { D x, y; C() : x(0), y(0) {} C(D x, D y) : x(x), y(y) {} C(complex c) : x(c.real()), y(c.imag()) {} inline C operator+(const C &c) const { return C(x + c.x, y + c.y); } inline C operator-(const C &c) const { return C(x - c.x, y - c.y); } inline C operator*(const C &c) const { return C(x * c.x - y * c.y, x * c.y + y * c.x); } }; const D PI = acosl(-1); vector fft(vector a, bool inv = false) { int n = int(a.size()); int h = 0; for(int i = 0; 1 << i < n; i++) h++; for(int i = 0; i < n; i++) { int j = 0; for(int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k); if(i < j) swap(a[i], a[j]); } for(int b = 1; b < n; b *= 2) { for(int j = 0; j < b; j++) { C w = C(polar(1, (2 * PI) / (2 * b) * j * (inv ? 1 : -1))); for(int k = 0; k < n; k += 2 * b) { C s = a[j + k], t = a[j + k + b] * w; a[j + k] = s + t, a[j + k + b] = s - t; } } } if(inv) { for(int i = 0; i < n; i++) a[i] = C(a[i].x / n, a[i].y / n); } return a; } vector fft(vector a, bool inv = false) { vector A(a.size()); for(int i = 0; i < int(a.size()); i++) A[i] = C(a[i], 0); return fft(A, inv); } vector conv(vector a, vector b) { int s = int(a.size() + b.size()) - 1; int t = 1; while(t < s) t *= 2; a.resize(t), b.resize(t); vector A = fft(a), B = fft(b); for(int i = 0; i < t; i++) A[i] = A[i] * B[i]; A = fft(A, true); a.resize(s); for(int i = 0; i < s; i++) a[i] = A[i].x; return a; } } // namespace FFT #line 3 "t.cpp" int L, M, N, Q; vector A, B; int main() { cin >> L >> M >> N; A.resize(N+1); B.resize(N+1); REP(i, L) { int x; cin >> x; A[x] += 1.0; } REP(i, M) { int x; cin >> x; B[N - x] += 1.0; } auto C = FFT::conv(A, B); cin >> Q; REP(v, Q) { ll res = ll(C[N + v] + 0.5); cout << res << "\n"; } }