//TLEč§£ #include #include #include struct cube{ int a, b, c; bool operator<(const cube&x){ return a == x.a ? b < x.b : a < x.a; } }; int main(){ int N,K,l,ans{0},i,k,j; std::cin >> N; std::vector A(N), B(N), C(N),dp(N); std::vector vc(N); int n{1}; for(i = 0; i < N; ++i){ std::cin >> A[i] >> B[i] >> C[i]; n*=3; } for(k = 0; k < n; ++k){ K=k; for(i = 0; i < N; ++i){ l = K % 3; if(l == 0) vc[i].a = A[i], vc[i].b = B[i], vc[i].c = C[i]; if(l == 1) vc[i].a = B[i], vc[i].b = C[i], vc[i].c = A[i]; if(l == 2) vc[i].a = C[i], vc[i].b = A[i], vc[i].c = B[i]; if(vc[i].a > vc[i].b) std::swap(vc[i].a, vc[i].b); K /= 3; } sort(vc.begin(),vc.end()); for(i = 0; i < N; ++i){ dp[i] = vc[i].c; for(j = 0; j < i; ++j){ if(vc[j].a <= vc[i].a && vc[j].b <= vc[i].b){ dp[i] = std::max(dp[i], dp[j] + vc[i].c); } } if(ans < dp[i]) ans = dp[i]; } } std::cout << ans << std::endl; }