#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int desll[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const int maxm = 1e5 + 7;
const double eps = 1e-4;
int m, n;
int ar[maxn];
int ans = 0;
int num[10], sum[5];
int f[5][5], mx = 1e5 + 7, all;
bool ma[5];
pair<pair<int, int>, int> pa[maxn];
int dfs(int x) {
  all += sum[x];
  ma[x] = 1;
  int mid = num[x] % 2;
  for (int i = 1; i <= 4; i++) {
    if (f[x][i] && !ma[i]) mid += dfs(i);
  }
  return mid;
}
void solve(int i) {
  memset(ma, 0, sizeof(ma));
  all = 0;
  int x = dfs(i);
  all /= 2;
  if (x == 4)
    ans = max(ans, all - mx);
  else
    ans = max(ans, all);
}
int main() {
  scanf("%d", &n);
  memset(num, 0, sizeof(num));
  memset(sum, 0, sizeof(sum));
  memset(f, 0, sizeof(f));
  ans = 0;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    sum[a] += b;
    sum[c] += b;
    num[a]++;
    num[c]++;
    f[a][c]++;
    f[c][a]++;
    pa[i] = make_pair(make_pair(a, b), c);
  }
  for (int i = 0; i < n; i++) {
    int a = pa[i].first.first, b = pa[i].first.second, c = pa[i].second;
    if (b < mx && a != c) {
      if (num[a] == 1 || num[c] == 1 || f[a][c] > 1) {
        mx = min(b, mx);
      } else {
        f[a][c]--;
        f[c][a]--;
        memset(ma, 0, sizeof(ma));
        dfs(a);
        if (ma[c]) mx = min(mx, b);
        f[c][a]++;
        f[a][c]++;
      }
    }
  }
  for (int i = 1; i <= 4; i++) solve(i);
  printf("%d\n", ans);
  return 0;
}
