#include using namespace std; struct Mast{ int n; int w; vector y; int &operator[](int i){ return y[i]; } int64_t area(){ return w*(int64_t)w; } Mast(){ cin>>n>>w; y.resize(n); for (auto &i: y){ cin>>i; } sort(y.begin(),y.end()); } }; int main(){ int gap; cin>>gap; Mast a,b,c; assert(a.w<=gap and b.w<=gap and c.w<=gap); b.y.emplace_back(max(max( a.w+a[a.n-1], b.w+b[b.n-1]), c.w+c[c.n-1])); b.n++; int ab_off=(max(0,(a.w+b.w)-gap) + 1)/2; int bc_off=(max(0,(b.w+c.w)-gap) + 1)/2; vector dp(b.n+1); for (int i=0; i=0; j--){ if (j==0 or b[j-1]+b.w<=b[i]){ int64_t score=b.area(); for (int ai=a.n,ay=b[i]-ab_off; ai--;){ if (a[ai]<=ay and (j==0 or (a[ai]>=b[j-1]+ab_off and a[ai]>b[j-1]))){ score+=a.area(); ay=a[ai]-a.w; } } for (int ci=c.n,cy=b[i]-bc_off; ci--;){ if (c[ci]<=cy and (j==0 or (c[ci]>=b[j-1]+bc_off and c[ci]>b[j-1]))){ score+=c.area(); cy=c[ci]-c.w; } } dp[i+1]=max(dp[i+1],dp[j]+score); } } // cerr<<"dp "<