#include int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int a[n], b[n], c[n]; for (int i = 0; i < n; i++) a[i] = ri(), b[i] = ri(), c[i] = ri(); int *list[6][3] = { {a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a} }; int dp[1 << n][n][6]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) for (int j = 0; j < 6; j++) dp[1 << i][i][j] = list[j][2][i]; for (int i = 0; i < 1 << n; i++) for (int j = 0; j < n; j++) if (i >> j & 1) for (int k = 0; k < 6; k++) for (int l = 0; l < n; l++) if (!(i >> l & 1)) for (int m = 0; m < 6; m++) if (list[m][0][l] <= list[k][0][j] && list[m][1][l] <= list[k][1][j]) dp[i | 1 << l][l][m] = std::max(dp[i | 1 << l][l][m], dp[i][j][k] + list[m][2][l]); int res = 0; for (auto &i : dp) for (auto &j : i) for (auto &k : j) res = std::max(res, k); printf("%d\n", res); return 0; }