#include #define REP(i, start, end) for (int64_t i=start, i##Len=(end); i < i##Len; ++i) #define REPR(i, start, end) for (int64_t i=start, i##Len=(end); i > i##Len; --i) using ll = int64_t; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll N; cin >> N; vector> box; ll x, y, z; REP(i, 0, N) { cin >> x >> y >> z; box.emplace_back(x, y, z); } ll bit_max = 1; REP(i, 0, N) bit_max *= 3; ll ans = 0; REP(bit, 0, bit_max) { ll b = bit; vector> box2; REP(i, 0, N) { tie(x, y, z) = box[i]; switch (b % 3) { case 0: box2.emplace_back(max(y, z), min(y, z), x); break; case 1: box2.emplace_back(max(x, z), min(x, z), y); break; case 2: box2.emplace_back(max(x, y), min(x, y), z); break; } b /= 3; } unordered_map dp1, dp2; sort(box2.begin(), box2.end(), greater>()); REP(i, 0, N) { dp1[100000000] = 0; tie(x, y, z) = box2[i]; for (auto p: dp1) { if (p.first >= y) dp2[y] = max(dp2[y], p.second + z); } swap(dp1, dp2); } for (auto p: dp1) ans = max(ans, p.second); } cout << ans << endl; }