#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
void go(vector<int> &x) {
  if (((int)(x.size())) == 13) {
    v.push_back(x);
    return;
  }
  v.push_back(x);
  for (int i = 1; i < 5; i++) {
    if (i == x[((int)(x.size())) - 1] || i == x[((int)(x.size())) - 2])
      continue;
    x.push_back(i);
    go(x);
    x.pop_back();
  }
}
vector<int> g[5][5];
vector<int> G[5][5];
map<pair<int, int>, int> mp;
int get(vector<int> x) {
  mp.clear();
  for (int i = 1; i < ((int)(x.size())); i++)
    mp[{min(x[i - 1], x[i]), max(x[i - 1], x[i])}]++;
  int val = 0;
  for (auto e : mp) {
    int x = e.first.first;
    int y = e.first.second;
    int ct = e.second;
    if (ct > ((int)(G[x][y].size()))) return 0;
    for (int i = 0; i < ct; i++) {
      val += G[x][y].back();
      G[x][y].pop_back();
    }
  }
  int a[5];
  memset(a, 0, sizeof a);
  for (int e : x) a[e]++;
  for (int i = 1; i < 5; i++)
    for (int j = i + 1; j < 5; j++) {
      if (((int)(G[i][j].size())) > 1 && (a[i] > 0 || a[j] > 0)) {
        a[i]++;
        a[j]++;
        while (((int)(G[i][j].size())) > 1) {
          val += G[i][j].back();
          G[i][j].pop_back();
          val += G[i][j].back();
          G[i][j].pop_back();
        }
      }
    }
  for (int i = 1; i < 5; i++)
    if (a[i])
      for (int e : G[i][i]) val += e;
  return val;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i < 5; i++) {
    vector<int> xx;
    xx.push_back(i);
    v.push_back(xx);
    for (int j = 1; j < 5; j++)
      if (i != j) {
        vector<int> x;
        x.push_back(i);
        x.push_back(j);
        go(x);
      }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c1, vv, c2;
    cin >> c1 >> vv >> c2;
    g[c1][c2].push_back(vv);
    if (c1 != c2) g[c2][c1].push_back(vv);
  }
  for (int i = 1; i < 5; i++)
    for (int j = 1; j < 5; j++) sort(g[i][j].begin(), g[i][j].end());
  int mx = 0;
  for (auto e : v) {
    for (int i = 1; i < 5; i++)
      for (int j = 1; j < 5; j++) G[i][j] = g[i][j];
    mx = max(mx, get(e));
  }
  cout << mx << '\n';
  return 0;
}
