#include using namespace std; using ll =long long; #define all(v) v.begin(),v.end() #define rep(i,a,b) for(int i=a;i=b;i--) ll INF=2e18; int main() { ll N,M,K;cin>>N>>M>>K; vector B(N); vector A(M); for(ll i=0;i>B[i]; for(ll i=0;i>A[i]; sort(all(B)); sort(all(A)); if(N C=B; B=A; A=C; } vector> b(N+M,vector (0)); vector> r(N+M,vector (0)); ll ind=0; map S; for(ll i=0;i> vec(0); for(auto p:b[w]) vec.push_back(make_pair(p,0)); for(auto p:r[w]) vec.push_back(make_pair(p,1)); vector R(x+y+1,0); vector Rind(0); sort(all(vec)); for(ll i=0;i d(x+y+1,0); for(ll i=x+y-1;i>=0;i--) { d[i]=d[i+1]; if(vec[i].second==1) d[i]-=vec[i].first; else d[i]+=vec[i].first; } ll g=max(x,y); vector> dp(y,vector (0)); vector> note(x+y+g+1,{INF,INF}); ll ri=-1; now=y-x; for(ll j=0;j (fb+1,INF); ll k=R[j+1]; if(note[k+g].second!=INF) { dp[ri+1][0]=d[j+1]-d[note[k+g].first]; if(note[k+g].second!=-1) { dp[ri+1][0]+=dp[note[k+g].second][note[k+g].first-Rind[note[k+g].second]]; } } for(ll h=1;h<=fb;h++) { k=R[j+h+1]; if(note[k+g].second!=INF) { dp[ri+1][h]=d[note[k+g].first]-d[j+h+1]; if(note[k+g].second!=-1) { dp[ri+1][h]+=dp[note[k+g].second].back(); } } dp[ri+1][h]=min(dp[ri+1][h],dp[ri+1][h-1]); } } if(vec[j].second==1) { now--; ri++; } else now++; } ans+=dp[y-1].back(); } cout<