#include #include #include using namespace std; bool check(int xa, int ya, int xb, int yb) { return (xa <= xb && ya <= yb) || (xa <= yb && ya <= xb); } int main() { int N; cin >> N; vector A(N), B(N), C(N); for (int i = 0; i < N; ++i) { cin >> A[i] >> B[i] >> C[i]; } vector > dp(1 << N, vector(3 * N)); for (int i = 0; i < N; ++i) { for (int j = 0; j < 3; ++j) { dp[1 << i][i + 2 * N] = (j == 0 ? A[i] : (j == 1 ? B[i] : C[i])); } } for (int i = 1; i < 1 << N; ++i) { for (int j = 0; j < N; ++j) { if (!((i >> j) & 1)) continue; int sub = i - (1 << j); for (int k = 0; k < N; ++k) { if (!((sub >> k) & 1)) continue; for (int x = 0; x < 3; ++x) { int xa = (x == 0 ? B[j] : (x == 1 ? C[j] : A[j])); int ya = (x == 0 ? C[j] : (x == 1 ? A[j] : B[j])); int za = (x == 0 ? A[j] : (x == 1 ? B[j] : C[j])); for (int y = 0; y < 3; ++y) { int xb = (y == 0 ? B[k] : (y == 1 ? C[k] : A[k])); int yb = (y == 0 ? C[k] : (y == 1 ? A[k] : B[k])); if (check(xa, ya, xb, yb)) { dp[i][j + x * N] = max(dp[i][j + x * N], dp[sub][k + y * N] + za); } } } } } } int ans = 0; for (int i = 0; i < 1 << N; ++i) { ans = max(ans, *max_element(dp[i].begin(), dp[i].end())); } cout << ans << endl; return 0; }