#include using namespace std; const int maxN = 100000; int memo[65536] = { 0 }; bool bA[maxN + 1] = { false }; bool bB[maxN + 1] = { false }; unsigned int A[maxN/32 + 1] = { 0 }; unsigned int B[maxN/32 + 1] = { 0 }; void fill_memo() { for (int i = 0; i != (1 << 16); ++i) { int cum = 0, j = i; while (j) { if (j & 1) ++cum; j >>= 1; } memo[i] = cum; } } void read_data(bool bT[], int L){ for (int i = 0, val = 0; i != L; ++i) { cin >> val; bT[val] = true; } } void fill_array(bool bS[], unsigned int T[], int N); int count_common(unsigned int A[], unsigned int B[], int N); inline int bit_count(unsigned int m) { return memo[m & 65535] + memo[m >> 16]; } inline void shift_array(unsigned int B[], int N) { for (int i = N / 32; i != 0; --i) { B[i] <<= 1; if (B[i - 1] >> 31) B[i] |= 1; } B[0] <<= 1; } template void disp(Array ar[], int N) { for (int i = 0; i <= N; ++i) cout << ar[i] << ' '; cout << endl; } int main() { fill_memo(); int L, M, N, Q; cin >> L >> M >> N; read_data(bA, L); read_data(bB, M); // disp(bA, N); // disp(bB, N); cin >> Q; fill_array(bA, A, N); fill_array(bB, B, N); // disp(A, N/32 + 1); // disp(B, N/32 + 1); for (int v = 0; v != Q; ++v) { cout << count_common(A, B, N) << '\n'; shift_array(B, N); } return 0; } void fill_array(bool bS[], unsigned int T[], int N) { unsigned int cum = 0, pow2 = 1; for (int i = 0; i <= N; ++i) { if (bS[i]) cum += pow2; pow2 <<= 1; if (i % 32 == 31) { T[i / 32] = cum; cum = 0; pow2 = 1; } } if (cum) T[N / 32] = cum; } int count_common(unsigned int A[], unsigned int B[], int N) { int end = N / 32 + 1; int count = 0; for (int i = 0; i != end; ++i) { count += bit_count(A[i] & B[i]); } return count; }