#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; os << "[" << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os << "]"; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } int L, M, N; vector A, B; int Q; void input() { cin >> L >> M >> N; A.clear(); A.resize(N, 0); B.clear(); B.resize(N, 0); for (int i = 0; i < L; i++) { int a; cin >> a; a--; A[a] = 1; } for (int i = 0; i < M; i++) { int b; cin >> b; b--; B[b] = 1; } cin >> Q; } const int X = 991; const ll mod = ll(1e9 + 7); ll pow(ll x, int n) { if (n == 0) return 1; if (n & 1) return x * pow(x, n - 1) % mod; return pow(x * x % mod, n / 2); } ll hash(const vector& h, int s, int t) { return (h[t] + mod - h[s] * pow(X, t - s) % mod) % mod; } void solve() { vector count_a(N + 1, 0); for (int i = 0; i < N; i++) { count_a[i + 1] = count_a[i] + (A[i] == 1); } vector hash_a(N + 1, 0); vector hash_b(N + 1, 0); for (int i = 0; i < N; i++) { hash_a[i + 1] = (ll(A[i]) + hash_a[i] * X % mod) % mod; hash_b[i + 1] = (ll(B[i]) + hash_b[i] * X % mod) % mod; } for (int q = 0; q < Q; q++) { //cerr << "q: " << q << endl; int ans = 0; for (int i = q; i < N; ) { if (A[i] == B[i - q]) { int j = 0; //cout << (hash(hash_a, i, i + (1<