#include using namespace std; using ll = long long; constexpr char newl = '\n'; constexpr ll INF = 1e15; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector< vector > v(3, vector(n)); for (int i = 0; i < n; i++) { cin >> v[0][i] >> v[1][i] >> v[2][i]; } vector< vector< vector > > dp(3, vector< vector >(n, vector(1 << n, -INF))); for (int i = 0; i < n; i++) { dp[0][i][1 << i] = v[0][i]; dp[1][i][1 << i] = v[1][i]; dp[2][i][1 << i] = v[2][i]; } for (int i = 1; i < (1 << n) - 1; i++) { for (int j = 0; j < n; j++) { if (i >> j & 1) { for (int k = 0; k < n; k++) { if (i >> k & 1) continue; for (int l = 0; l < 3; l++) { if (dp[l][j][i] <= -INF) continue; ll minv_j = min(v[(l + 1) % 3][j], v[(l + 2) % 3][j]); ll maxv_j = max(v[(l + 1) % 3][j], v[(l + 2) % 3][j]); for (int m = 0; m < 3; m++) { ll minv_k = min(v[(m + 1) % 3][k], v[(m + 2) % 3][k]); ll maxv_k = max(v[(m + 1) % 3][k], v[(m + 2) % 3][k]); if (minv_k <= minv_j && maxv_k <= maxv_j) { dp[m][k][i | (1 << k)] = max(dp[m][k][i | (1 << k)], dp[l][j][i] + v[m][k]); } } } } } } } ll ans = -INF; for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < (1 << n); k++) { ans = max(ans, dp[i][j][k]); } } } cout << ans << newl; return 0; }