#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, sum;
int d[maxn], vis[maxn], del[maxn], check[maxn];
struct node {
  int id, v, val;
};
vector<node> g[maxn], edge[maxn];
void euler(int u, int fa) {
  check[u] = 1;
  for (auto v : g[u]) {
    if (del[v.id] || vis[v.id]) continue;
    vis[v.id] = 1;
    sum += v.val;
    euler(v.v, u);
  }
}
bool can() {
  int cnt = 0;
  for (int i = 1; i <= 4; i++) {
    if (check[i] && (d[i] & 1)) cnt++;
  }
  return cnt <= 2;
}
void init() {
  memset(vis, 0, sizeof(vis));
  memset(check, 0, sizeof(check));
  sum = 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int c1, c2, v;
    cin >> c1 >> v >> c2;
    g[c1].push_back(node{i, c2, v});
    g[c2].push_back(node{i, c1, v});
    d[c1]++;
    d[c2]++;
    edge[i].push_back(node{c1, c2, v});
  }
  int ans = 0;
  for (int i = 1; i <= 4; i++) {
    init();
    euler(i, -1);
    if (can()) ans = max(ans, sum);
  }
  for (int i = 1; i <= n; i++) {
    del[i - 1] = 0;
    del[i] = 1;
    d[edge[i][0].id]--;
    d[edge[i][0].v]--;
    for (int j = 1; j <= 4; j++) {
      init();
      euler(j, -1);
      if (can()) ans = max(ans, sum);
    }
    d[edge[i][0].id]++;
    d[edge[i][0].v]++;
  }
  cout << ans << endl;
  return 0;
}
