#include <bits/stdc++.h>
using namespace std;
inline long long Getint() {
  char ch = getchar();
  long long x = 0, fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    (x *= 10) += ch ^ 48;
    ch = getchar();
  }
  return x * fh;
}
namespace Task1 {
struct nod {
  int a, b;
  long long w;
  nod(int x = 0, int y = 0, long long z = 0) {
    a = x;
    b = y;
    w = z;
  }
} A[205];
vector<nod> R;
vector<int> V;
int n, m, prt[205], d[205];
long long val[5][5], cnt[5][5], mx = 0;
inline int Getfa(int x) { return prt[x] == x ? x : prt[x] = Getfa(prt[x]); }
inline void Merge(int x, int y) {
  x = Getfa(x);
  y = Getfa(y);
  prt[x] = y;
}
int fa[5];
inline int F(int x) { return fa[x] == x ? x : fa[x] = F(fa[x]); }
inline bool Check() {
  int su = 0, bl = 0;
  for (int i = 1; i <= m; i++) fa[i] = i, su += d[i] & 1;
  for (int i = 1; i <= m; i++)
    for (int j = i; j <= m; j++)
      if (cnt[i][j]) fa[F(i)] = F(j);
  for (int i = 1; i <= m; i++) bl += F(i) == i;
  if (bl > 1) return 0;
  if (su == 0 || su == 2) return 1;
  return 0;
}
void Dfs(int u, long long res) {
  if (u == R.size()) {
    if (Check()) mx = max(mx, res);
    return;
  }
  Dfs(u + 1, res);
  int x = R[u].a, y = R[u].b;
  cnt[x][y]--;
  cnt[y][x]--;
  d[x]--;
  d[y]--;
  Dfs(u + 1, res - R[u].w);
  d[x]++;
  d[y]++;
  cnt[x][y]++;
  cnt[y][x]++;
}
inline long long Maintain(int len) {
  int x, y, z;
  long long Ans = 0;
  mx = 0;
  m = len;
  for (int i = 1; i <= m; i++) d[i] = 0;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= m; j++) val[i][j] = 1 << 30;
  for (int i = 0; i <= int(R.size()) - 1; i++) {
    x = R[i].a;
    y = R[i].b;
    z = R[i].w;
    val[x][y] = min(val[x][y], R[i].w);
    val[y][x] = val[x][y];
    cnt[x][y]++;
    cnt[y][x] = cnt[x][y];
    Ans += R[i].w;
    d[x]++;
    d[y]++;
  }
  R.clear();
  for (int i = 1; i <= m; i++)
    for (int j = i; j <= m; j++) {
      if (val[i][j] == (1 << 30)) continue;
      R.push_back(nod(i, j, val[i][j]));
    }
  Dfs(0, Ans);
  return mx;
}
inline void Solve() {
  int x, y, z;
  n = Getint();
  for (int i = 1; i <= 4; i++) prt[i] = i;
  long long Ans = 0;
  for (int i = 1; i <= n; i++) {
    A[i].a = x = Getint();
    A[i].w = Getint();
    A[i].b = y = Getint();
    Merge(x, y);
  }
  for (int i = 1; i <= 4; i++) {
    if (Getfa(i) != i) continue;
    R.clear();
    V.clear();
    for (int j = 1; j <= 4; j++)
      if (Getfa(i) == Getfa(j)) V.push_back(j);
    for (int j = 1; j <= n; j++) {
      x = A[j].a;
      y = A[j].b;
      x = lower_bound(V.begin(), V.end(), x) - V.begin();
      y = lower_bound(V.begin(), V.end(), y) - V.begin();
      if ((x == V.size() || V[x] != A[j].a) &&
          (y == V.size() || V[y] != A[j].b))
        continue;
      R.push_back(nod(x + 1, y + 1, A[j].w));
    }
    Ans = max(Ans, Maintain(V.size()));
  }
  cout << Ans << '\n';
}
}  // namespace Task1
int main() {
  Task1::Solve();
  return 0;
}
