#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T sgn(T a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
const double pi = acos(-1.0);
int n;
int m;
vector<pair<int, pair<int, int>>> v[5];
int was[5], wase[100];
map<pair<int, int>, int> b;
map<pair<int, int>, vector<int>> a;
int ans = 0;
vector<int> cert;
void dfs(int x, int l) {
  was[x]++;
  int cnt = 0;
  for (auto& to : v[x]) {
    if (wase[to.second.second]) continue;
    wase[to.second.second] = true;
    dfs(to.first, l + to.second.first);
    wase[to.second.second] = false;
    cnt++;
  }
  if (cnt == 0) {
    for (auto q : b) {
      if (was[q.first.first] > 0 || was[q.first.second] > 0) {
        l += q.second;
      }
    }
    ans = max(ans, l);
  }
  was[x]--;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c1, c2, val;
    cin >> c1 >> val >> c2;
    if (c1 > c2) swap(c1, c2);
    a[make_pair(c1, c2)].push_back(val);
  }
  int num = 0;
  for (auto q : a) {
    sort((q.second).begin(), (q.second).end());
    int s = 0;
    int r = q.first.first == q.first.second
                ? 0
                : (2 - ((int)(q.second).size()) % 2);
    while (((int)(q.second).size()) > r) {
      s += q.second.back();
      q.second.pop_back();
    }
    if (s > 0) {
      b[q.first] = s;
    }
    for (auto x : q.second) {
      v[q.first.first].push_back(make_pair(q.first.second, make_pair(x, num)));
      v[q.first.second].push_back(make_pair(q.first.first, make_pair(x, num)));
      num++;
    }
  }
  for (int i = 1; i <= 4; i++) {
    dfs(i, 0);
  }
  cout << ans << endl;
  return 0;
}
