#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5e5 + 15;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
int n;
vector<int> v[5][5];
long long s[5][5];
int cnt[5][5];
long long ans = 0;
bool visited[5];
void solve(vector<pair<int, int> >& edges, int n) {
  bool k1 = true, k2 = true;
  int a = edges[0].first;
  int b = edges[0].second;
  long long sumE = 0;
  memset(visited, 0, sizeof(visited));
  for (int i = 1; i <= 4; ++i)
    for (int j = i; j <= 4; ++j) cnt[i][j] = 0;
  for (int i = 0; i <= n; ++i) {
    if (a == edges[i].first)
      a = edges[i].second;
    else if (a == edges[i].second)
      a = edges[i].first;
    else
      k1 = false;
    if (b == edges[i].first)
      b = edges[i].second;
    else if (b == edges[i].second)
      b = edges[i].first;
    else
      k2 = false;
    visited[edges[i].first] = visited[edges[i].second] = true;
    ++cnt[edges[i].first][edges[i].second];
  }
  if (!(k1 || k2)) return;
  long long cur = 0;
  for (int i = 1; i <= 4; ++i) {
    if (visited[i]) cur += s[i][i];
    for (int j = i + 1; j <= 4; ++j)
      if (visited[i] || visited[j]) {
        cur += s[i][j];
        if ((v[i][j].size() - cnt[i][j]) & 1) cur -= v[i][j][0];
      }
  }
  ans = max(ans, cur);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  mt19937 rnd(clock());
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x, y, z;
    cin >> x >> z >> y;
    if (x > y) swap(x, y);
    v[x][y].push_back(z);
  }
  vector<pair<int, int> > edges;
  for (int i = 1; i <= 4; ++i)
    for (int j = i; j <= 4; ++j) {
      sort(v[i][j].begin(), v[i][j].end());
      for (int x : v[i][j]) s[i][j] += x;
      for (int s = 1; s <= min(2, (int)v[i][j].size()); ++s)
        edges.push_back(make_pair(i, j));
    }
  for (int i = 0; i <= 100000; ++i) {
    random_shuffle(edges.begin(), edges.end());
    for (int i = 0; i < edges.size(); ++i) solve(edges, i);
  }
  cout << ans << '\n';
  return 0;
}
