#include <bits/stdc++.h>
using namespace std;
const int INF32 = 0x3f3f3f3f;
const int MAXN = 120;
int n, ans, mx, du[5], f[5][5], sum[5];
bool vis[5];
struct edge {
  int a, b, c;
} edges[MAXN];
int dfs(int u, int& s) {
  vis[u] = true;
  int ret = (du[u] & 1);
  s += sum[u];
  for (int i = 1; i <= 4; ++i)
    if (!vis[i] && f[u][i]) ret += dfs(i, s);
  return ret;
}
void solve(int u) {
  memset(vis, false, sizeof(vis));
  int s = 0;
  int x = dfs(u, s);
  if (x == 4)
    ans = max(ans, s / 2 - mx);
  else
    ans = max(ans, s / 2);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    edges[i] = edge{a, b, c};
    ++f[a][c], ++f[c][a], ++du[a], ++du[c];
    sum[a] += b, sum[c] += b;
  }
  mx = INF32;
  for (int i = 0; i < n; ++i) {
    int a = edges[i].a, b = edges[i].b, c = edges[i].c;
    if (b >= mx || a == c) continue;
    if (du[a] == 1 || du[c] == 1 || f[a][c] > 1) {
      mx = min(mx, b);
    } else {
      --f[a][c], --f[c][a];
      memset(vis, 0, sizeof(vis));
      int s = 0;
      dfs(a, s);
      if (vis[c]) mx = min(mx, b);
      ++f[a][c], ++f[c][a];
    }
  }
  for (int i = 1; i <= 4; ++i) solve(i);
  cout << ans << endl;
}
