#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
long long n, ans = 0, a[N], l[N], r[N];
long long par[8], sz[8], cost[8], od[8], cnt[22][22], deg[22];
vector<long long> v[15];
map<int, pair<int, int> > mp;
map<pair<int, int>, int> mp2;
int findPar(int node) {
  if (par[node] == node) return node;
  return par[node] = findPar(par[node]);
}
void mergeCom(int node, int node2) {
  int led = findPar(node), led2 = findPar(node2);
  if (led == led2) return;
  if (sz[led] < sz[led2]) swap(led, led2);
  par[led2] = led, sz[led] += sz[led2];
}
int vis[5];
void solve2(int i) {
  if (i == 5) {
    long long res = 0, odd = 0;
    vector<int> dg(6, 0);
    for (int j = 1; j <= 4; j++) par[j] = j, sz[j] = 1;
    for (int j = 1; j <= 4; j++) {
      for (int jj = j + 1; jj <= 4; jj++) {
        if (vis[j] && vis[jj] && cnt[j][jj]) mergeCom(j, jj);
      }
    }
    for (int j = 1; j <= 4; j++) {
      dg[j] = deg[j];
      for (int jj = j + 1; jj <= 4; jj++) {
        if (findPar(j) != findPar(jj) && vis[j] && vis[jj]) return;
      }
    }
    for (int j = 1; j <= 4; j++) {
      for (int jj = j + 1; jj <= 4; jj++) {
        if (vis[j] != vis[jj]) {
          if (vis[j]) {
            dg[j] -= cnt[j][jj];
          } else {
            dg[jj] -= cnt[j][jj];
          }
        }
      }
    }
    for (int j = 1; j <= 4; j++) {
      if (vis[j]) {
        if (dg[j] % 2) odd++;
        for (auto it : v[mp2[{j, j}]]) res += it;
        for (int jj = j + 1; jj <= 4; jj++) {
          if (vis[jj] && cnt[j][jj]) {
            for (int k = 0; k < v[mp2[{j, jj}]].size() && k < cnt[j][jj]; k++) {
              res += v[mp2[{j, jj}]][k];
            }
          }
        }
      }
    }
    if (odd == 0 || odd == 2) {
      ans = max(ans, res);
    }
    return;
  }
  vis[i] = 1;
  solve2(i + 1);
  vis[i] = 0;
  solve2(i + 1);
}
void solve(int i) {
  if (i == 10) {
    solve2(1);
    return;
  }
  if (v[i].size()) {
    long long tmp = v[i].back();
    v[i].pop_back();
    int vv = mp[i].first, uu = mp[i].second;
    deg[vv]--, deg[uu]--, cnt[vv][uu]--;
    solve(i + 1);
    v[i].push_back(tmp);
    deg[vv]++, deg[uu]++;
    cnt[vv][uu]++;
  }
  solve(i + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int c = 0;
  for (int i = 1; i <= 4; i++) {
    for (int j = i; j <= 4; j++) {
      mp[c] = {i, j};
      mp2[{i, j}] = c;
      c++;
    }
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> a[i] >> r[i];
    int vv = l[i], u = r[i], id;
    if (u < vv) swap(vv, u);
    id = mp2[{vv, u}];
    cnt[vv][u]++;
    deg[u]++, deg[vv]++;
    v[id].push_back(a[i]);
  }
  for (int i = 0; i < 12; i++) {
    sort(v[i].begin(), v[i].end(), greater<long long>());
  }
  solve(0);
  cout << ans << '\n';
  return 0;
}
