#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int n; vector a, b, c; struct Bottom { ll a, b, h; Bottom(ll _a, ll _b, ll _h) :a(_a), b(_b), h(_h) {}; }; struct RectangularSolid { ll a, b, c; vector s; RectangularSolid(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(c, a), max(c, a), b); } }; bool check(Bottom bt, Bottom tp) { return bt.a >= tp.a and bt.b >= tp.b; } vector vr; vector>> dp; ll dfs(ll S, ll pre, ll bt) { if (pre != -1 and dp[S][pre][bt] != -1) return dp[S][pre][bt]; if (S == (1 << n) - 1) return 0; ll res = 0; for (int bit = 0; bit < n; bit++) { if (!(S >> bit & 1)) { for (int i = 0; i < 3; i++) { if (pre == -1 or check(vr[pre].s[bt], vr[bit].s[i])) { chmax(res, dfs(S | (1 << bit), bit, i) + vr[bit].s[i].h); } } } } if(pre != -1) dp[S][pre][bt] = res; return res; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ scanf("%d", &n); a.resize(n), b.resize(n), c.resize(n); dp.resize(1 << n, vector>(n, vector(3, -1))); for (int i = 0; i < n; i++) { scanf("%lld %lld %lld", &a[i], &b[i], &c[i]); vr.emplace_back(a[i], b[i], c[i]); } cout << dfs(0, -1, -1) << endl; return 0; }