#include <bits/stdc++.h>
using namespace std;
int d[5];
int N;
int s[101], e[101], l[101];
int sum[5];
int f[5][5];
bool vis[5];
int all = 0;
int dfs(int x) {
  int temp = d[x] % 2;
  all += sum[x];
  vis[x] = true;
  for (int i = 1; i <= 4; i++) {
    if (!vis[i] && f[x][i] && x != i) {
      temp += dfs(i);
    }
  }
  return temp;
}
int main() {
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    cin >> s[i] >> l[i] >> e[i];
    if (s[i] != e[i]) {
      d[s[i]]++;
      d[e[i]]++;
    }
    f[s[i]][e[i]]++;
    f[e[i]][s[i]]++;
    sum[s[i]] += l[i];
    sum[e[i]] += l[i];
  }
  int MIN = 1e9 + 7;
  for (int i = 1; i <= N; i++) {
    if (s[i] != e[i] && (d[s[i]] % 2 == 1 || d[e[i]] % 2 == 1)) {
      if (f[s[i]][e[i]] == 1) {
        for (int i = 1; i <= 4; i++) vis[i] = false;
        f[s[i]][e[i]]--;
        f[e[i]][s[i]]--;
        dfs(s[i]);
        if (vis[e[i]] == true) MIN = min(MIN, l[i]);
        f[s[i]][e[i]]++;
        f[e[i]][s[i]]++;
      } else
        MIN = min(MIN, l[i]);
    }
  }
  for (int i = 1; i <= 4; i++) {
    for (int i = 1; i <= 4; i++) vis[i] = false;
    all = 0;
    int temp = dfs(i);
    all /= 2;
    if (temp == 4)
      ans = max(ans, all - MIN);
    else
      ans = max(ans, all);
  }
  cout << ans;
  return 0;
}
