#include <bits/stdc++.h>
using namespace std;
const int _ = 105;
inline int read() {
  char ch = '!';
  int z = 1, num = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') z = -1, ch = getchar();
  while (ch <= '9' && ch >= '0')
    num = (num << 3) + (num << 1) + ch - '0', ch = getchar();
  return z * num;
}
int n, f[_][_][5][5];
int main() {
  n = read();
  memset(f, -63, sizeof(f));
  for (int i = 1; i <= n; ++i) {
    int a = read(), c = read(), b = read();
    f[i][i][a][b] = f[i][i][b][a] = c;
  }
  int ans = 0;
  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\n", ans);
  return 0;
}
