#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 #include #include #include #include #include #define endl codeforces #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair; using tii = std::tuple; using pll = std::pair; using tll = std::tuple; template using vec = std::vector; template using vvec = vec>; template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template T make_v(T init) { return init; } template auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec(s, v); } template struct multi_dem_array { using type = std::array::type, Head>; }; template struct multi_dem_array { using type = std::array; }; template using mdarray = typename multi_dem_array::type; namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } const std::size_t SIZE = 16; mdarray dp; mdarray used; const ll inf = 5e15; ll calc(ll s, ll idx, ll sel, const vec &v) { if (idx != -1 && used[s][idx][sel]) return dp[s][idx][sel]; if (idx != -1) used[s][idx][sel] = true; ll ret = 0; auto [ a, b, c ] = (idx == -1 ? tll(inf, inf, inf) : v[idx]); pll pv[] = { pll(a, b), pll(a, c), pll(b, c), }; auto [ pa, pb ] = pv[sel]; for (ll i = 0; i < v.size(); i++) { ll mask = 1ll << i; if (s & mask) continue; auto [ ai, bi, ci ] = v[i]; pll pvi[] = { pll(ai, bi), pll(ai, ci), pll(bi, ci) }; ll height[] = { ci, bi, ai, }; for (ll j = 0; j < 3; j++) { auto [ l1, l2 ] = pvi[j]; bool ok = false; if (l1 <= pa && l2 <= pb) ok = true; if (l1 <= pb && l2 <= pa) ok = true; if (!ok) continue; chmax(ret, calc(s | mask, i, j, v) + height[j]); } } if (idx != -1) dp[s][idx][sel] = ret; return ret; } int main() { ll n; std::cin >> n; vec abc(n); for (auto &&e : abc) { ll a, b, c; std::cin >> a >> b >> c; e = tll(a, b, c); } std::cout << calc(0, -1, 0, abc) << "\n"; return 0; }