/*** author: yuji9511 ***/ #include using namespace std; using ll = long long; using lpair = pair; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i void print(H&& h, T&&... t){cout<(t)...);} typedef struct { ll h; ll w; ll c; } P; struct SegmentTreeMax { private: int n; vector node; public: SegmentTreeMax(ll N){ ll sz = N; n = 1; while(n < sz) n *= 2; node.resize(2*n-1, -INF); rep(i,0,sz) node[i+n-1] = 0; rrep(i,n-2,0) node[i] = max(node[2*i+1], node[2*i+2]); } void update(ll x, ll val){ x += (n-1); node[x] = val; while(x > 0){ x = (x-1)/2; node[x] = max(node[2*x+1], node[2*x+2]); } } void add(ll x, ll val){ x += n-1; node[x] += val; while(x > 0){ x = (x-1)/2; node[x] = max(node[2*x+1], node[2*x+2]); } } ll getMax(ll a, ll b){ ll res = -INF; a += n; b += n; while(a < b){ if(b & 1){ b -= 1; res = max(res, node[b-1]); } if(a & 1){ res = max(res, node[a-1]); a++; } a >>= 1; b >>= 1; } return res; } ll getval(ll x){ return node[x + n-1]; } }; SegmentTreeMax sg(1000010); int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll A[20], B[20], C[20]; rep(i,0,N) cin >> A[i] >> B[i] >> C[i]; ll ans = 0; ll vv = 1; rep(i,0,N) vv *= 3; rep(bit,0,vv){ vector v(N,0); ll idx = 0; ll b = bit; while(b > 0){ v[idx] = b % 3; b /= 3; idx++; } vector

lp; rep(i,0,N){ if(v[i] == 0){ ll v1 = B[i], v2 = C[i]; if(v1 > v2) swap(v1,v2); lp.push_back({v1,v2, A[i]}); }else if(v[i] == 1){ ll v1 = B[i], v2 = A[i]; if(v1 > v2) swap(v1,v2); lp.push_back({v1,v2, C[i]}); }else{ ll v1 = A[i], v2 = C[i]; if(v1 > v2) swap(v1,v2); lp.push_back({v1,v2, B[i]}); } } sort(lp.begin(), lp.end(), [](P l1, P l2){ if(l1.h == l2.h){ return l1.w < l2.w; } return l1.h < l2.h; }); // rep(i,0,N){ // print(lp[i].h, lp[i].w, lp[i].c); // } // print("==="); ll dp[20] = {}; rep(i,0,N){ dp[i] = sg.getMax(1, lp[i].w+1) + lp[i].c; // if(bit == 7) print(i); ll v = sg.getval(lp[i].w); v = max(v, dp[i]); sg.update(lp[i].w, v); } rep(i,0,N){ sg.update(lp[i].w, 0); } ans = max(ans, dp[N-1]); } print(ans); }