#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> lowest(4, vector<int>(4, 1000000005));
vector<vector<int>> sum(4, vector<int>(4, 0));
vector<vector<int>> rmv(4, vector<int>(4, 0));
vector<vector<int>> cnt(4, vector<int>(4, 0));
vector<int> visited(4, 0);
int bfs(int start) {
  queue<int> q{};
  set<int> sVis{};
  q.push(start);
  sVis.insert(start);
  visited[start] = 1;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      if (!visited[i] && cnt[curr][i] - rmv[curr][i] > 0) {
        visited[i] = 1;
        sVis.insert(i);
        q.push(i);
      }
    }
  }
  int suma = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = i; j < 4; j++) {
      if (sVis.find(i) != sVis.end() && sVis.find(j) != sVis.end()) {
        suma += sum[i][j] - (cnt[i][j] > 0 ? lowest[i][j] * rmv[i][j] : 0);
      }
    }
  }
  int nepCnt = 0;
  for (int i = 0; i < 4; i++) {
    if (sVis.find(i) != sVis.end()) {
      int susjeda = 0;
      for (int k = 0; k < 4; k++) {
        susjeda += cnt[i][k];
        if (i != k && rmv[i][k] && cnt[i][k] > 0) susjeda--;
      }
      nepCnt += susjeda % 2;
    }
  }
  if (nepCnt == 0 || nepCnt == 2) {
    return suma;
  } else {
    return -10000000;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) {
    int b, v, e;
    cin >> b >> v >> e;
    b--;
    e--;
    sum[b][e] += v;
    cnt[b][e]++;
    lowest[b][e] = min(lowest[b][e], v);
    lowest[e][b] = min(lowest[e][b], v);
    cnt[e][b]++;
    if (b != e) {
      sum[e][b] += v;
    }
  }
  int opt = 0;
  for (int i = 0; i < (1 << 16); i++) {
    rmv = vector<vector<int>>(4, vector<int>(4, 0));
    visited = vector<int>(4, 0);
    for (int j = 0; j < 16; j++) {
      if ((i & (1 << j)) != 0) {
        rmv[j / 4][j % 4] = 1;
        rmv[j % 4][j / 4] = 1;
      }
    }
    for (int k = 0; k < 4; k++) {
      if (!visited[k]) {
        opt = max(opt, bfs(k));
      }
    }
  }
  printf("%d", opt);
}
