func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 138;   int n, Ans, x, y, z, GG[N][N][5][5];   int main() {     memset(GG, -63, sizeof(GG));     cin >> n;     int i, j, k, p;     for (i = 1; i <= n; ++i) {       cin >> x >> y >> z;       GG[i][i][z][x] = GG[i][i][x][z] = y;     }     for (i = n; i >= 1; --i)       for (j = i; j <= n; ++j)         for (int x = 1; x <= 4; ++x)           for (int y = 1; y <= 4; ++y)             for (k = i; k <= j; ++k) {               GG[i][j][x][y] =                   max(GG[i][j][x][y], max(GG[i][k][x][y], GG[k + 1][j][x][y]));               for (p = 1; p <= 4; ++p)                 GG[i][j][x][y] =                     max(GG[i][j][x][y], max(GG[i][k][x][p] + GG[k + 1][j][p][y],                                             GG[i][k][p][y] + GG[k + 1][j][x][p]));               Ans = max(Ans, GG[i][j][x][y]);             }     cout << Ans << endl;     return 0;   }   