#define MOD_TYPE 1 #pragma region Macros #include using namespace std; #if 1 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #if 0 #include #include #include #include using namespace __gnu_pbds; using namespace __gnu_cxx; template using extset = tree, rb_tree_tag, tree_order_statistics_node_update>; #endif #if 0 #include #include using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif using ll = long long int; using ld = long double; using pii = pair; using pll = pair; using pld = pair; template using smaller_queue = priority_queue, greater>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr ld PI = acos(-1.0); constexpr ld EPS = 1e-7; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template constexpr istream &operator>>(istream &is, pair &p) noexcept { is >> p.first >> p.second; return is; } template constexpr ostream &operator<<(ostream &os, pair &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion random_device seed_gen; mt19937_64 engine(seed_gen()); // -------------------------------------- template struct BellmanFord { struct edge { int from, to; T cost; }; int V; T INF; vector E; vector d; vector negative; BellmanFord(int V, T INF = 4e18) : V(V), INF(INF) { d.resize(V); negative.resize(V); } void add_edge(int a, int b, T c, bool directed = true) { E.push_back(edge{a, b, c}); if (!directed) E.push_back(edge{b, a, c}); } void calc(int s) { fill(d.begin(), d.end(), INF); d[s] = 0; bool update = true; while (update) { update = false; for (auto e : E) { if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } } } bool calc_and_find_negative_loop(int s, int g = -1) { fill(all(d), INF); fill(all(negative), false); d[s] = 0; rep(i, V) { bool update = false; for (auto e : E) { if (d[e.from] != LINF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; if (i == V - 1) negative[e.from] = negative[e.to] = true; } } if (!update) return false; } if (g == -1) { rep(i, V) { if (negative[i]) return true; } return false; } else { return negative[g]; } } bool find_any_negative_loop() { vector d_(V); rep(i, V) for (auto e : E) { if (d_[e.to] > d_[e.from] + e.cost) { d_[e.to] = d_[e.from] + e.cost; if (i == V - 1) return true; } } return false; } }; void solve() { int n; cin >> n; int a[16][3]; rep(i, n) rep(j, 3) cin >> a[i][j]; BellmanFord bf(n * 3 + 1, INF); const int S = n * 3; rep(i, n) rep(j, n) { if (i == j) continue; rep(k, 3) rep(l, 3) { int h1 = a[i][k], h2 = a[j][l]; int a1, b1; if (k == 0) a1 = a[i][1], b1 = a[i][2]; if (k == 1) a1 = a[i][0], b1 = a[i][2]; if (k == 2) a1 = a[i][0], b1 = a[i][1]; int a2, b2; if (l == 0) a2 = a[j][1], b2 = a[j][2]; if (l == 1) a2 = a[j][0], b2 = a[j][2]; if (l == 2) a2 = a[j][0], b2 = a[j][1]; if ((a1 < a2 and b1 < b2) or (a1 < b2 and b1 < a2)) bf.add_edge(i + n * k, j + n * l, -h2); } } rep(i, n) rep(k, 3) { bf.add_edge(S, i + n * k, -a[i][k]); } bf.calc(S); int ans = 0; rep(i, n * 3) chmax(ans, -bf.d[i]); cout << ans << "\n"; } int main() { solve(); }