#include <bits/stdc++.h>
using namespace std;
vector<int> h[5][5];
int ans, t, n, cnt[5][5], f[5], s[5][5], res, rt, c, d, pre[5], o, g[5];
int ffind(int x) {
  if (pre[x] != x) pre[x] = ffind(pre[x]);
  return pre[x];
}
void union_(int x, int y) {
  x = ffind(x);
  y = ffind(y);
  if (x != y) pre[x] = y, d--;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, v, w;
    cin >> u >> w >> v;
    if (u > v) swap(u, v);
    h[u][v].push_back(w);
    cnt[u][v]++;
    s[u][v] += w;
  }
  for (int i = 1; i <= 4; i++)
    for (int j = i; j <= 4; j++) sort(h[i][j].begin(), h[i][j].end());
  for (int i = 1; i <= 14; i++) {
    for (int j = 1; j <= 4; j++) f[j] = (bool)(i & (1 << (j - 1)));
    res = d = 0;
    for (int j = 1; j <= 4; j++)
      if (f[j]) res += s[j][j], d++;
    for (int j = 1; j <= 4; j++)
      for (int k = j + 1; k <= 4; k++)
        if (f[j] && f[k] && cnt[j][k]) d--, res += s[j][k];
    if (d <= 1) ans = max(ans, res);
  }
  res = 0;
  for (int i = 1; i <= 4; i++) res += s[i][i];
  for (int i = 0; i < 64; i++) {
    res = 0;
    d = 4;
    c = 0;
    bool flag = true;
    for (int j = 1; j <= 4; j++) pre[j] = j, g[j] = 0, res += s[j][j];
    for (int j = 1; j <= 4; j++)
      for (int k = j + 1; k <= 4; k++) {
        o = (bool)(i & (1 << c));
        c++;
        res += s[j][k];
        if (o) {
          if (cnt[j][k] & 1)
            union_(j, k);
          else if (cnt[j][k] == 0)
            flag = false;
          else
            res -= h[j][k][0], union_(j, k);
          g[j] ^= 1;
          g[k] ^= 1;
        } else {
          if (cnt[j][k] & 1) {
            res -= h[j][k][0];
            if (cnt[j][k] > 1) union_(j, k);
          } else if (cnt[j][k])
            union_(j, k);
        }
      }
    if (g[1] && g[2] && g[3] && g[4]) flag = false;
    if (d > 1) flag = false;
    if (flag) ans = max(ans, res);
  }
  cout << ans << endl;
}
