#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, h, x, g, b; cin >> n >> h >> x; cin >> g; vector

d; rep(_, g) { int gi; cin >> gi; d.emplace_back(gi, 1); } cin >> b; rep(_, b) { int bi; cin >> bi; d.emplace_back(bi, -1); } sort(all(d)); if (d.empty() || d.back().first != n) { d.emplace_back(n, 0); } VVI dp(x); dp[0].emplace_back(0); int now = 0; constexpr int INF = 1001001001; auto trans = [&](int i, int j, int ni, int nj) { if (nj > dp[ni].size()) { dp[ni].resize(nj + 1, -INF); dp[ni][nj] = dp[i][j]; } else if (nj == dp[ni].size()) { dp[ni].emplace_back(dp[i][j]); } else { chmax(dp[ni][nj], dp[i][j]); } }; for(auto [i, c] : d) { // [now, i+1-x] -> i+1-x if (now < i + 1 - x) { int l = min((i + 1 - x) - now, x - 1); rep(i, l) { rep(j, dp[i].size()) { trans(i, j, i+1, j); } dp[i].clear(); } rotate(dp.begin(), dp.begin() + l, dp.end()); now = i + 1 - x; } while(now != i) { dp.emplace_back(); rep(j, dp[0].size()) { trans(0, j, 1, j); trans(0, j, x, j + 1); } dp.erase(dp.begin()); now++; } rep(j, dp[0].size()) dp[0][j] += c; } int ans = -INF; rrep(j, min(dp[0].size(), h + 1)) chmax(ans, dp[0][j]); cout << ans << '\n'; }