#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, h, x, g, b; cin >> n >> h >> x >> g; vector G(g), ca; cin >> G >> b; vector B(b); cin >> B; ca.reserve(2 * x * (g + b)); for(auto &&v : G){ for(int d = -(x - 1); d + 1 <= x; d++){ int nv = v + d; if(nv < 0 || nv > n) continue; ca.emplace_back(nv); } } for(auto &&v : B){ for(int d = -(x - 1); d + 1 <= x; d++){ int nv = v + d; if(nv < 0 || nv > n) continue; ca.emplace_back(nv); } } for(int i = 0; i < min(x, n); i++){ ca.emplace_back(i); ca.emplace_back(n - i); } sort(ca.begin(), ca.end()); ca.erase(unique(ca.begin(), ca.end()), ca.end()); int m = ca.size(), i = 0; vector tb(m); for(auto &&v : G){ while(ca[i] < v) i++; tb[i] = 1; } i = 0; for(auto &&v : B){ while(ca[i] < v) i++; tb[i] = -1; } h = min({h, m, b}); vector> dp(m, vector(h + 1, -(1 << 30))); dp[0][h] = 0; for(int i = 0; i + 1 < m; i++){ for(int j = 0; j <= h; j++){ dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + tb[i + 1]); } if(i + x < m){ for(int j = 1; j <= h; j++){ dp[i + x][j - 1] = max(dp[i + x][j - 1], dp[i][j] + tb[i + x]); } } } cout << *max_element(dp.back().begin(), dp.back().end()) << '\n'; }