#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b #define vl vector #define vii vector> #define vll vector> #define vvi vector> #define vvl vector> #define vvii vector>> #define vvll vector>> #define vst vector #define pii pair #define pll pair #define pb push_back #define all(x) (x).begin(),(x).end() #define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end()) #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005; const ll INF=15LL<<58; ll a[55],b[55],c[55]; ll N; ll ans=0; vector> S; void DFS(int u,ll x,ll y,int tar,bool f){ if(u>tar) return; if(u==tar){ if(f==0) S.pb(mp(x,y)); else{ auto it=lower_bound(all(S),mp(-x,-INF)); if(it!=S.end()){ chmax(ans,y+(*it).se); } } return; } DFS(u+1,x+a[u],y,tar,f); DFS(u+2,x-c[u+1],y+b[u+1],tar,f); } int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); cin>>N; for(int i=0;i>a[i]>>b[i]>>c[i]; } DFS(0,0,0,N/2,0); sort(all(S)); for(int i=si(S)-2;i>=0;i--) chmax(S[i].se,S[i+1].se); DFS(N/2,0,0,N,1); S.clear(); if(N>1){ DFS(0,0,0,N/2-1,0); sort(all(S)); for(int i=si(S)-2;i>=0;i--) chmax(S[i].se,S[i+1].se); DFS(N/2-1,0,0,N,1); } cout<