#include <bits/stdc++.h>
using namespace std;
int n, c1[101], c2[101], v[101], f[101], DEG[101];
void GoHome() {
  cin >> n;
  for (int i = (1); i <= (n); ++i) cin >> c1[i] >> v[i] >> c2[i];
  for (int i = (1); i <= (4); ++i) f[i] = i;
  for (int i = (1); i <= (n); ++i) {
    if (f[c1[i]] != f[c2[i]]) {
      int t = min(f[c1[i]], f[c2[i]]);
      int x = f[c1[i]], y = f[c2[i]];
      for (int j = (4); j >= (1); --j)
        if (f[j] == x || f[j] == y) f[j] = t;
    }
  }
  int res = 0;
  for (int i = (1); i <= (4); ++i)
    if (f[i] == i) {
      for (int j = (1); j <= (4); ++j) DEG[j] = 0;
      int ans = 0;
      for (int j = (1); j <= (n); ++j)
        if (f[c1[j]] == i) {
          ans += v[j];
          if (c1[j] == c2[j]) continue;
          DEG[c1[j]]++;
          DEG[c2[j]]++;
        }
      int cntOdd = 0;
      for (int j = (1); j <= (4); ++j)
        if (f[j] == i && DEG[j] % 2) cntOdd++;
      if (cntOdd < 3) {
        res = max(res, ans);
        continue;
      }
      int t = 1e9;
      for (int j = (1); j <= (n); ++j)
        if (c1[j] != c2[j] && DEG[c1[j]] % 2 && DEG[c2[j]] % 2 &&
            DEG[c1[j]] > 1 && DEG[c2[j]] > 1 && t > v[j])
          t = v[j];
      ans -= t;
      { cerr << "t" << '=' << t << '\n'; };
      res = max(res, ans);
    }
  cout << res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  GoHome();
}
