#include <bits/stdc++.h>
using namespace std;
vector<int> v[5][5], adj[5];
vector<pair<int, int> > x;
int visited[5];
void dfs(int node) {
  if (visited[node]) return;
  visited[node] = 1;
  for (int i = 0; i < adj[node].size(); i++) dfs(adj[node][i]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int c1, val, c2;
    scanf("%d %d %d", &c1, &val, &c2);
    v[c1][c2].push_back(val);
  }
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 4; j++) {
      sort(v[i][j].begin(), v[i][j].end());
      reverse(v[i][j].begin(), v[i][j].end());
      x.push_back(make_pair(i, j));
    }
  }
  long long ans = 0;
  for (int mask = 0; mask < (1 << 16); mask++) {
    int deg[5] = {0};
    long long sum[5][5];
    memset(sum, 0, sizeof(sum));
    vector<int> p[5][5];
    for (int i = 1; i <= 4; i++) {
      for (int j = 1; j <= 4; j++) {
        p[i][j] = v[i][j];
      }
      adj[i].clear();
    }
    int flag = 1;
    for (int i = 0; i < 16; i++) {
      if ((1 << i) & mask) {
        int ff = x[i].first;
        int ss = x[i].second;
        if (!p[ff][ss].size()) {
          flag = 0;
          continue;
        }
        p[ff][ss].pop_back();
      }
    }
    if (!flag) continue;
    for (int i = 1; i <= 4; i++) {
      for (int j = 1; j <= 4; j++) {
        if (p[i][j].size()) {
          adj[i].push_back(j);
          adj[j].push_back(i);
        }
        for (int k = 0; k < p[i][j].size(); k++) {
          sum[i][j] += p[i][j][k];
        }
      }
    }
    for (int i = 1; i <= 4; i++) {
      for (int j = 1; j <= 4; j++) {
        visited[j] = 0;
        deg[j] = 0;
      }
      dfs(i);
      long long curr = 0;
      for (int j = 1; j <= 4; j++) {
        for (int k = 1; k <= 4; k++) {
          if (visited[j] && visited[k]) {
            curr += sum[j][k];
            deg[j] += p[j][k].size();
            deg[k] += p[j][k].size();
          }
        }
      }
      int odd = 0;
      for (int i = 1; i <= 4; i++) {
        if (deg[i] % 2) odd++;
      }
      if (odd == 0 || odd == 2) ans = max(ans, curr);
    }
  }
  printf("%lld", ans);
}
