#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr int MOD = 1000000007; struct cube{ pll surface[3]; ll height[3]; }; bool ok(cube x,int i,cube y,int j){ bool res = (x.surface[i].first <= y.surface[j].first && x.surface[i].second <= y.surface[j].second); res = res || (x.surface[i].first <= y.surface[j].second && x.surface[i].second <= y.surface[j].first); return res; } int n; vector>> dp; vector Cube; ll dfs(ll mask,int last=-1,int i=-1){ if(last != -1 && dp[mask][last][i] != -1) return dp[mask][last][i]; if(mask == (1<>next & 1) continue; rep(j,3){ if(last == -1 or ok(Cube[last],i,Cube[next],j)){ res = max(res,dfs(mask|(1<> n; Cube.resize(n); rep(i,n){ int a,b,c; cin >> a >> b >> c; Cube[i].surface[0] = P(a,b); Cube[i].surface[1] = P(b,c); Cube[i].surface[2] = P(c,a); Cube[i].height[0] = c; Cube[i].height[1] = a; Cube[i].height[2] = b; } dp.assign(1<>(n,vector(3,-1))); cout << dfs(0) << endl; return 0; }