#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1000000007) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = 1000000007) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
vector<long long> v;
long long w[1003];
long long maxx;
long long vis[1003];
long long deg[10];
vector<long long> edge[10][10];
long long self[100];
void dfs(long long p) {
  v.push_back(p);
  vis[p] = 1;
  for (long long i = 1; i <= 4; i++) {
    if (p != i) {
      if (edge[p][i].size() > 0 && vis[i] == 0) {
        dfs(i);
      }
    }
  }
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long p, wt, q;
    cin >> p >> wt >> q;
    if (p == q) {
      self[p] += wt;
      continue;
    }
    deg[p]++;
    deg[q]++;
    edge[p][q].push_back(wt);
    edge[q][p].push_back(wt);
  }
  long long maxx = -1;
  for (long long i = 1; i <= 4; i++) {
    if (vis[i] == 0) {
      v.clear();
      dfs(i);
      long long sum = 0;
      for (auto e : v) {
        if (deg[e] % 2 == 1) {
          sum++;
        }
      }
      if (sum == 0 || sum == 2) {
        long long ans = 0;
        for (auto e : v) {
          ans += self[e];
        }
        for (long long i = 0; i < v.size(); i++) {
          for (long long j = i + 1; j < v.size(); j++) {
            if (i != j) {
              for (auto e : edge[v[i]][v[j]]) {
                ans += e;
              }
            }
          }
        }
        maxx = max(maxx, ans);
      } else {
        long long ans = 0;
        for (auto e : v) {
          ans += self[e];
        }
        for (long long i = 0; i < v.size(); i++) {
          for (long long j = i + 1; j < v.size(); j++) {
            if (i != j) {
              for (auto e : edge[v[i]][v[j]]) {
                ans += e;
              }
            }
          }
        }
        for (long long i = 0; i < v.size(); i++) {
          for (long long j = i + 1; j < v.size(); j++) {
            if (i != j) {
              if (edge[v[i]][v[j]].size() == 1) {
                maxx = max(maxx,
                           ans - edge[v[i]][v[j]][0] - self[v[i]] - self[v[j]]);
              } else if (edge[v[i]][v[j]].size() % 2 == 1) {
                sort(edge[v[i]][v[j]].begin(), edge[v[i]][v[j]].end());
                maxx = max(maxx, ans - edge[v[i]][v[j]][0]);
              } else if (edge[v[i]][v[j]].size() > 0) {
                sort(edge[v[i]][v[j]].begin(), edge[v[i]][v[j]].end());
                maxx = max(maxx, ans - edge[v[i]][v[j]][0]);
              }
            }
          }
        }
      }
    }
  }
  cout << maxx << "\n";
}
