#include <bits/stdc++.h>
using namespace std;
int flag[6], temp[6], val[6][6][106], s[6][6], cnt[6][6], fa[6],
    a[10] = {1, 1, 1, 1, 2, 2, 2, 3, 3, 4},
    b[10] = {1, 2, 3, 4, 2, 3, 4, 3, 4, 4};
int comp(int c, int d) { return c > d; }
int Find(int x) {
  if (fa[x] == 0) return x;
  return fa[x] = Find(fa[x]);
}
int Jud(int x, int y) {
  int i, sum, t1, t2;
  sum = 0;
  memset(fa, 0, sizeof(fa));
  memset(temp, 0, sizeof(temp));
  for (i = 0; i <= 9; i++) {
    if (x & (1 << i) && i != y && cnt[a[i]][b[i]]) {
      temp[a[i]] = temp[b[i]] = 1;
      t1 = Find(a[i]);
      t2 = Find(b[i]);
      if (t1 != t2) {
        fa[t1] = t2;
        sum--;
      }
    }
  }
  for (i = 1; i <= 4; i++) sum += temp[i];
  if (sum != 1) return 0;
  return 1;
}
int main(void) {
  int n, i, j, x, y, t, t1, t2, sum, ans, bet, js;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &x, &t, &y);
    if (x > y) swap(x, y);
    if (x == y)
      cnt[x][y] = 1, val[x][y][1] += t, s[x][y] += t;
    else
      val[x][y][++cnt[x][y]] = t, s[x][y] += t;
  }
  for (i = 1; i <= 4; i++) {
    for (j = i + 1; j <= 4; j++) sort(val[i][j] + 1, val[i][j] + cnt[i][j] + 1);
  }
  sum = bet = 0;
  for (i = 0; i <= 1023; i++) {
    ans = sum = js = 0;
    memset(fa, 0, sizeof(fa));
    memset(flag, 0, sizeof(flag));
    for (j = 0; j <= 9; j++) {
      if (i & (1 << j)) {
        if (cnt[a[j]][b[j]] == 0) continue;
        flag[a[j]] += cnt[a[j]][b[j]], flag[b[j]] += cnt[a[j]][b[j]];
        t1 = Find(a[j]);
        t2 = Find(b[j]);
        ans += s[a[j]][b[j]];
        if (t1 != t2) {
          fa[t1] = t2;
          sum--;
        }
      }
    }
    for (j = 1; j <= 4; j++) {
      js += (flag[j] % 2);
      sum += (flag[j] != 0);
    }
    if (sum != 1) continue;
    if (js != 4)
      bet = max(bet, ans);
    else {
      for (j = 0; j <= 9; j++) {
        if (i & (1 << j)) {
          if (flag[a[j]] % 2 && flag[b[j]] % 2 && cnt[a[j]][b[j]] &&
              a[j] != b[j] && (Jud(i, j) || cnt[a[j]][b[j]] >= 2))
            bet = max(bet, ans - val[a[j]][b[j]][1]);
        }
      }
    }
  }
  printf("%d\n", bet);
  return 0;
}
