#include #ifdef LOCAL #include #else #define debug(...) void(0) #endif using namespace std; typedef long long ll; #define all(x) begin(x), end(x) constexpr int INF = (1 << 30) - 1; constexpr long long IINF = (1LL << 60) - 1; constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; template istream& operator>>(istream& is, vector& v) { for (auto& x : v) is >> x; return is; } template ostream& operator<<(ostream& os, const vector& v) { auto sep = ""; for (const auto& x : v) os << exchange(sep, " ") << x; return os; } template bool chmin(T& x, U&& y) { return y < x and (x = forward(y), true); } template bool chmax(T& x, U&& y) { return x < y and (x = forward(y), true); } template void mkuni(vector& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } template int lwb(const vector& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); } const int MAX = 10010; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, H, X; cin >> N >> H >> X; int G; cin >> G; vector g(G); for (int& x : g) cin >> x; int B; cin >> B; vector b(B); for (int& x : b) cin >> x; sort(all(g)); sort(all(b)); vector cand; cand.emplace_back(0); cand.emplace_back(N); for (int& x : g) { for (int i = 0; i <= X; i++) { if (x - i > 0) { cand.emplace_back(x - i); } } } for (int& x : b) { for (int i = 0; i <= X; i++) { if (x - i > 0) { cand.emplace_back(x - i); } } } mkuni(cand); int len = cand.size(); chmin(H, MAX); vector dp(len, vector(H + 1, -INF)); dp[0][0] = 0; for (int i = 0, p = 0, q = 0, k = 0; i < len; i++) { while (p < G and g[p] < cand[i]) p++; while (q < B and b[q] < cand[i]) q++; int add = 0; if (p < G and g[p] == cand[i]) add++; if (q < B and b[q] == cand[i]) add--; int to = cand[i] + X; while (k < len and cand[k] < to) k++; for (int j = 0; j <= H; j++) { int& val = dp[i][j]; if (val == -INF) continue; val += add; if (i + 1 < len) chmax(dp[i + 1][j], val); if (k < len and cand[k] == to and j + 1 <= H) chmax(dp[k][j + 1], val); } } int ans = *max_element(all(dp.back())); cout << ans << '\n'; return 0; }