#include <bits/stdc++.h>
using namespace std;
struct edge {
  int c1, c2;
  long long val;
} ed[201];
bool cmp(int i, int j) { return ed[i].val < ed[j].val; }
vector<int> vis;
vector<int> val(5);
vector<int> rem;
vector<int> g[201];
int kk = 0;
void dfs(int u, int &viol, long long &ans) {
  vis[u] = 1;
  ans += 2 * val[u];
  for (int i : g[u]) {
    if (rem[i]) continue;
    long long wt = ed[i].val;
    ans += wt;
  }
  int cnt = g[u].size();
  for (int i : g[u]) {
    int v = ed[i].c1 ^ ed[i].c2 ^ u;
    if (rem[i]) {
      cnt--;
      continue;
    }
    if (vis[v]) continue;
    dfs(v, viol, ans);
  }
  viol += cnt % 2;
}
int main() {
  int n;
  cin >> n;
  map<pair<int, int>, int> mpp;
  int cnt = 0;
  for (int i = 1; i <= 4; i++) {
    for (int j = i + 1; j <= 4; j++) {
      mpp[make_pair(i, j)] = cnt++;
    }
  }
  vector<vector<int> > types(cnt + 1);
  for (int i = 0; i < n; i++) {
    int c1, c2;
    long long v;
    cin >> c1 >> v >> c2;
    if (c1 > c2) swap(c1, c2);
    ed[i] = {c1, c2, v};
    if (c1 == c2) {
      val[c1] += v;
    } else {
      g[c1].push_back(i);
      g[c2].push_back(i);
      types[mpp[make_pair(c1, c2)]].push_back(i);
    }
  }
  for (int i = 0; i < cnt; i++) {
    sort(types[i].begin(), types[i].end(), cmp);
  }
  long long ans = 0;
  for (int i = 0; i < 1 << cnt; i++) {
    rem = vector<int>(n + 1);
    for (int j = 0; j < cnt; j++) {
      if ((i & (1 << j)) && !types[j].empty()) {
        rem[types[j][0]] = 1;
        if (i == 16) {
          kk = 0;
        }
      }
    }
    for (int k = 1; k <= 4; k++) {
      vis = vector<int>(5);
      long long curans = 0;
      int violated = 0;
      dfs(k, violated, curans);
      kk++;
      if (violated <= 2) {
        ans = max(ans, curans / 2);
      }
    }
  }
  cout << ans << '\n';
}
