#include <bits/stdc++.h>
using namespace std;
int n, ans;
int f[110][110][6][6];
inline int read() {
  int x = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
void pre() {
  n = read();
  memset(f, -63, sizeof(f));
  int a, b, c;
  for (register int i = 1; i <= n; i++) {
    a = read(), b = read(), c = read();
    f[i][i][a][c] = f[i][i][c][a] = b;
  }
}
inline void upmax(int &a, int b) {
  if (b > a) a = b;
}
void work() {
  for (register int i = n; i; i--)
    for (register int j = i; j <= n; j++)
      for (register int x = 1; x <= 4; x++)
        for (register int y = 1; y <= 4; y++) {
          for (register int l = i; l < j; l++) {
            upmax(f[i][j][x][y], max(f[i][l][x][y], f[l + 1][j][x][y]));
            for (register int k = 1; k <= 4; k++) {
              upmax(f[i][j][x][y], f[i][l][x][k] + f[l + 1][j][k][y]);
              upmax(f[i][j][x][y], f[i][l][k][y] + f[l + 1][j][x][k]);
            }
          }
          upmax(ans, f[i][j][x][y]);
        }
  printf("%d\n", ans);
}
int main() {
  pre();
  work();
  return 0;
}
