typedef long long ll; typedef long double ld; #include using namespace std; struct p { ll a,b,c; }; int main() { ll n; std::cin >> n; vector

elm(n*6); vector> edges(n*6); for (int i = 0; i < n; i++) { vector tmp(3); std::cin >> tmp[0]>>tmp[1]>>tmp[2]; for (int j = 0; j < 6; j++) { elm[6*i+j].a = tmp[0]; elm[6*i+j].b = tmp[1]; elm[6*i+j].c = tmp[2]; next_permutation(tmp.begin(),tmp.end()); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(i==j)continue; for (int ii = 0; ii < 6; ii++) { for (int jj = 0; jj < 6; jj++) { ll l = 6*i+ii; ll r = 6*j+jj; // l < r if(elm[l].a<=elm[r].a&&elm[l].b<=elm[r].b){ edges[l].push_back(r); } } } } } vector used(n,false); int ans = 0; function rec = [&] (int now, int height) { height += elm[now].c; ans = max(ans,height); for (auto e : edges[now]) { if(used[e/6])continue; used[e/6] = true; rec(e, height); used[e/6] = false; } }; for (int i = 0; i < n*6; i++) { used[i/6] = true; rec(i,0); used[i/6] = false; } std::cout << ans << std::endl; }