#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int f[maxn][maxn][5][5];
int main() {
  int n, ans = 0;
  cin >> n;
  memset(f, -0x3f, sizeof(f));
  for (int i = 1; i <= n; i++) {
    int a, b, c;
    cin >> a >> c >> b;
    f[i][i][a][b] = f[i][i][b][a] = c;
  }
  for (int i = n; i; i--) {
    for (int j = i; j <= n; j++) {
      for (int x = 1; x <= 4; x++) {
        for (int y = 1; y <= 4; y++) {
          for (int k = i; k <= j + 1; k++) {
            f[i][j][x][y] =
                max(f[i][j][x][y], max(f[i][k][x][y], f[k + 1][j][x][y]));
            for (int p = 1; p <= 4; ++p) {
              f[i][j][x][y] =
                  max(f[i][j][x][y], max(f[i][k][p][y] + f[k + 1][j][x][p],
                                         f[i][k][x][p] + f[k + 1][j][p][y]));
            }
          }
          ans = max(ans, f[i][j][x][y]);
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}
