#include <bits/stdc++.h>
using namespace std;
int n, ctr = 0, inf = 1e9;
int code[45], val[10] = {}, rev[10], deg[5] = {}, mn[10];
void precal() {
  for (int i = 0; i < 10; ++i) mn[i] = inf;
  for (int i = 1; i <= 4; ++i) {
    for (int j = i; j <= 4; ++j) {
      code[i * 10 + j] = ctr;
      rev[ctr] = i * 10 + j;
      ++ctr;
    }
  }
}
bool seen[5], seen2[10];
int tval[10], trm;
vector<int> comp;
void dfs(int cur) {
  seen[cur] = 1;
  comp.push_back(cur);
  int cd;
  for (int j = 1; j <= 4; ++j) {
    if (j == cur) {
      trm += tval[code[j * 11]];
      continue;
    }
    if (j <= cur)
      cd = code[j * 10 + cur];
    else
      cd = code[cur * 10 + j];
    if (!tval[cd]) continue;
    if (!seen2[cd]) {
      trm += tval[cd];
      seen2[cd] = 1;
    }
    if (seen[j]) continue;
    dfs(j);
  }
  return;
}
int cal(int mask) {
  int ans = 0;
  int tdeg[5] = {};
  memset(seen2, 0, sizeof seen2);
  for (int i = 1; i <= 4; ++i) {
    tdeg[i] = deg[i];
    seen[i] = 0;
  }
  for (int i = 0; i < 10; ++i) {
    tval[i] = val[i];
    if (((mask >> i) & 1) == 0) continue;
    if (!val[i]) return 0;
    tval[i] -= mn[i];
    int cur = rev[i];
    int n1 = cur / 10, n2 = cur % 10;
    --tdeg[n1];
    --tdeg[n2];
  }
  for (int i = 1; i <= 4; ++i) {
    if (seen[i]) continue;
    comp.clear();
    trm = 0;
    dfs(i);
    int no = 0;
    for (auto i : comp) {
      if (tdeg[i] % 2) ++no;
    }
    if (no != 0 && no != 2) continue;
    ans = max(ans, trm);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  precal();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int l, r, v;
    cin >> l >> v >> r;
    if (r < l) swap(l, r);
    int cur = code[l * 10 + r];
    val[cur] += v;
    mn[cur] = min(mn[cur], v);
    deg[l]++;
    deg[r]++;
  }
  int mx = (1 << 10), ans = 0;
  for (int mask = 0; mask < mx; ++mask) {
    ans = max(ans, cal(mask));
  }
  cout << ans;
  return 0;
}
