#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int N,H,X; cin>>N>>H>>X; vector> t; rep(i,2){ int a; cin>>a; rep(j,a){ int pos; cin>>pos; t.emplace_back(pos,-i*2+1); } } sort(t.begin(),t.end()); int aans = 0; if(t.size()>0 && t.back().first==N){ aans += t.back().second; t.pop_back(); } t.emplace_back(0,0); t.emplace_back(N,0); sort(t.begin(),t.end()); { vector D(t.size()-1); rep(i,t.size()-1){ D[i] = t[i+1].first - t[i].first; D[i] = min(D[i],12); } rep(i,t.size()-1){ t[i+1].first = t[i].first + D[i]; } } N = t.back().first; H = min(N,H); vector cost(N+10); rep(i,t.size()){ cost[t[i].first] = t[i].second; } vector dp(X+5,vector(H+1,-Inf32)); dp[0][0] = 0; rep(i,N){ dp.push_back(vector(H+1,-Inf32)); rep(j,H+1){ dp[1][j] = max(dp[1][j],dp[0][j]+cost[i+1]); if(i+X<=N&&j!=H){ dp[X][j+1] = max(dp[X][j+1],dp[0][j] + cost[i+X]); } } dp.erase(dp.begin()); } int ans = -Inf32; rep(i,H+1)ans = max(ans,dp[0][i]); //cout<