#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 private:
  vector<int> p, rank, setSize;
  int numSets;

 public:
  UnionFind(int N) {
    setSize.assign(N, 1);
    numSets = N;
    rank.assign(N, 0);
    p.assign(N, 0);
    for (int i = 0; i < N; i++) p[i] = i;
  }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (!isSameSet(i, j)) {
      numSets--;
      int x = findSet(i), y = findSet(j);
      if (rank[x] > rank[y]) {
        p[y] = x;
        setSize[x] += setSize[y];
      } else {
        p[x] = y;
        setSize[y] += setSize[x];
        if (rank[x] == rank[y]) rank[y]++;
      }
    }
  }
  int numDisjointSets() { return numSets; }
  int sizeOfSet(int i) { return setSize[findSet(i)]; }
};
int sum[4];
int deg[4];
int main() {
  int n;
  cin >> n;
  int a[n], v[n], b[n];
  for (int ctr1 = 0; ctr1 < n; ++ctr1) cin >> a[ctr1] >> v[ctr1] >> b[ctr1];
  UnionFind uf(4);
  int mi = 101010;
  for (int ctr1 = 0; ctr1 < n; ++ctr1) {
    uf.unionSet(a[ctr1] - 1, b[ctr1] - 1);
    ++deg[a[ctr1] - 1];
    ++deg[b[ctr1] - 1];
    if (a[ctr1] != b[ctr1]) mi = min(mi, v[ctr1]);
  }
  for (int ctr1 = 0; ctr1 < n; ++ctr1) sum[uf.findSet(a[ctr1] - 1)] += v[ctr1];
  cout << (*max_element(sum, sum + 4)) -
              (((deg[0] & 1) && (deg[1] & 1) && (deg[2] & 1) && (deg[3] & 1) &&
                uf.numDisjointSets() == 1)
                   ? mi
                   : 0);
  return 0;
}
