#include #define REP(i, n) for(int i = 0;i < n;i++) #define ll long long using namespace std; //typedef vectorvec; //typedef vectorvec; //typedef vector mat; typedef pair P; typedef pair LP; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1000000000; const ll LINF = 1000000000000000000;//1e18 const ll MOD = 1000000007; const double PI = acos(-1.0); const double EPS = 1e-10; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } //template inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;}; struct edges{ ll a, b, h; edges(ll _a, ll _b, ll _h): a(_a), b(_b), h(_h){ } }; struct Cuboid{ ll a, b, c; vector S; Cuboid(ll _a, ll _b, ll _c): a(_a), b(_b), c(_c){ S.emplace_back(min(a, b), max(a, b), c); S.emplace_back(min(b, c), max(b, c), a); S.emplace_back(min(a, c), max(a, c), b); } }; void solve(){ int N; cin >> N; vector cu; REP(i,N){ int a, b, c; cin >> a >> b >> c; cu.emplace_back(a, b, c); } vector>> dp(1<>(N, vector(3, -1))); auto dfs = [&](auto && self, ll State, int pre, int surface) -> ll{ if(pre != -1 && dp[State][pre][surface] != -1) return dp[State][pre][surface]; if(__builtin_popcountll(State) == N) return 0; ll res = 0; REP(i, N){ if(State >> i & 1) continue; REP(j,3){ if(pre == -1 || (cu[i].S[j].a >= cu[pre].S[surface].a && cu[i].S[j].b >= cu[pre].S[surface].b)){ chmax(res, self(self, State | (1LL << i), i, j) + cu[i].S[j].h); } } } if(pre != -1) dp[State][pre][surface] = res; return res; }; cout << dfs(dfs, 0, -1, -1) << endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); // int T; cin >> T; REP(t,T) solve(); }