#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long int to, cost;
};
void add_edge(vector<vector<edge> >& G, long long int u, long long int v,
              long long int c) {
  G[u].push_back((edge){v, c});
  G[v].push_back((edge){u, c});
}
const long long int INF = 1e18;
const long long int MOD = 1e9 + 7;
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  long long int len = v.size();
  s << "[";
  for (long long int i = 0; i < len; i++) {
    s << v[i];
    if (i < len - 1) s << " ";
  }
  s << "]";
  return s;
}
void bfs(const vector<vector<edge> >& G, vector<bool>& used, long long int s) {
  queue<long long int> que;
  que.push(s);
  while (!que.empty()) {
    long long int i = que.front();
    que.pop();
    for (long long int j = (0); j < (G[i].size()); ++j) {
      edge e = G[i][j];
      if (!used[e.to]) {
        used[e.to] = true;
        que.push(e.to);
      }
    }
  }
}
void dijkstra(const vector<vector<edge> >& G, vector<long long int>& d,
              long long int s) {
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int> >,
                 greater<pair<long long int, long long int> > >
      que;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  que.push(pair<long long int, long long int>(0, s));
  while (!que.empty()) {
    long long int temp_cost = que.top().first;
    long long int from = que.top().second;
    que.pop();
    if (d[from] < temp_cost) continue;
    for (long long int i = 0; i < G[from].size(); i++) {
      edge e = G[from][i];
      if (d[e.to] > d[from] + e.cost) {
        d[e.to] = d[from] + e.cost;
        que.push(pair<long long int, long long int>(d[e.to], e.to));
      }
    }
  }
}
signed main() {
  long long int n;
  cin >> n;
  vector<vector<edge> > G(4, vector<edge>());
  for (long long int i = (0); i < (n); ++i) {
    long long int c1, c2, v;
    cin >> c1 >> v >> c2;
    c1--;
    c2--;
    add_edge(G, c1, c2, v);
  }
  long long int ans = 0;
  for (long long int i = (0); i < (4); ++i) {
    vector<bool> used(4, false);
    bfs(G, used, i);
    long long int s = 0;
    long long int odd_n = 0;
    for (long long int j = (0); j < (4); ++j) {
      if (used[j]) {
        for (long long int k = (0); k < ((long long int)((G[j]).size())); ++k) {
          s += G[j][k].cost;
        }
        if ((long long int)((G[j]).size()) % 2 == 1) {
          odd_n++;
        }
      }
    }
    s /= 2;
    if (odd_n == 4) {
      vector<vector<long long int> > d(4, vector<long long int>(4, INF));
      for (long long int m = (0); m < (4); ++m) {
        dijkstra(G, d[m], m);
        sort((d[m]).begin(), (d[m]).end());
      }
      long long int MIN = INF;
      for (long long int m = (0); m < (4); ++m) {
        MIN = min(MIN, d[i][1]);
      }
      s -= MIN;
    }
    ans = max(ans, s);
  }
  cout << ans << endl;
  return 0;
}
