#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #pragma warning(disable:4996) typedef long long ll; typedef unsigned long long ull; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; ll dp[1 << 16][16][3]; void solve() { int n; scanf("%d", &n); vector a(n * 3); int i,j,k; for (i = 0; i < n; i++) { scanf("%d%d%d", &a[3*i], &a[3*i+1], &a[3*i+2]); } for (i = 0; i < (1 << n); i++) { for (j = 0; j < n; j++) { for (k = 0; k < 3; k++) { dp[i][j][k] = -1; } } } ll ans = 0; for (j = 0; j < n; j++) { for (k = 0; k < 3; k++) { dp[1 << j][j][k] = a[3 * j + k]; ans = MAX(ans, dp[1 << j][j][k]); } } for (i = 0; i < (1 << n); i++) { for (j = 0; j < n; j++) { for (k = 0; k < 3; k++) { if (dp[i][j][k] >= 0) { int p; for (p = 0; p < n; p++) { if (i & (1 << p)) continue; int k2; for (k2 = 0; k2 < 3; k2++) { int k_1 = (k + 1) % 3, k_2 = (k + 2) % 3; int k2_1 = (k2 + 1) % 3, k2_2 = (k2 + 2) % 3; if (MIN(3 * j + k_1, 3 * j + k_2) <= MIN(3 * p + k2_1, 3 * p + k2_2)) { if (MAX(3 * j + k_1, 3 * j + k_2) <= MAX(3 * p + k2_1, 3 * p + k2_2)) { dp[i | (1 << p)][p][k2] = dp[i][j][k] + a[3 * p + k2]; ans = MAX(ans, dp[i | (1 << p)][p][k2]); } } } } } } } } printf("%lld\n", ans); return; } int main(int argc, char* argv[]) { #if 1 solve(); #else int T; scanf("%d", &T); int t; for(t=0; t