#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; ll solve(vector a,vector b,vector c) { ll ans=-INF; //Aをすべて取る ll count=0; ll A=0; for(ll i=0;i r(c.size()+1); for(ll i=1;i<=c.size();i++) { r[i]=r[i-1]+c[i-1]; } reverse(all(b)); ll B=0; for(ll i=0;i<=b.size();i++) { ll sum=A*i; ll ind=lower_bound(all(c),-B)-c.begin(); sum+=r.back()-r[ind]+B*(c.size()-ind); ans=max(ans,sum); if(i a,vector b,vector c) { ll ans=-INF; //Aが0以上のみ取る ll count=0; ll A=0; reverse(all(a)); for(ll i=0;i=0) { count++; A+=a[i]; } } for(ll i=0;i r(c.size()+1); for(ll i=1;i<=c.size();i++) { r[i]=r[i-1]+c[i-1]; } reverse(all(b)); ll B=0; for(ll i=0;i<=b.size();i++) { ll sum=A*i; ll ind=lower_bound(all(c),-B)-c.begin(); sum+=r.back()-r[ind]+B*(c.size()-ind); ans=max(ans,sum); if(i>na>>nb>>nc; vector A(na),B(nb),C(nc); for(ll i=0;i>A[i]; for(ll i=0;i>B[i]; for(ll i=0;i>C[i]; sort(all(A)); sort(all(B)); sort(all(C)); ll ans=-INF; vector> vec(3); vec[0]=A; vec[1]=B; vec[2]=C; for(ll i=0;i<3;i++) { ans=max(ans,solve(vec[i],vec[(i+1)%3],vec[(i+2)%3])); ans=max(ans,solve2(vec[i],vec[(i+1)%3],vec[(i+2)%3])); } cout<