#include #include #include using namespace std; int W; long A[55],B[55],C[55]; vector >X; void dfs(int d,int lim,long x,long y) { if(d==lim) { X.push_back(make_pair(y,x)); return; } dfs(d+1,lim,x,y+A[d]); if(d+2<=lim)dfs(d+2,lim,x+B[d+1],y-C[d+1]); } main() { cin>>W; for(int i=0;i>A[i]>>B[i]>>C[i]; if(W==1) { cout<<0<){W/2-1,W/2}) { dfs(0,mid,0,0); sort(X.rbegin(),X.rend()); vector >A; long pre=0; for(pairp:X) { if(prep:X) { vector >::iterator it=lower_bound(A.begin(),A.end(),make_pair(-p.first,0L)); if(it!=A.end())ans=max(ans,p.second+it->second); } X.clear(); } cout<