#include <bits/stdc++.h>
using namespace std;
int cost;
int visited[5];
multiset<int> adj[5][5];
void dfs(int u) {
  visited[u] = 1;
  for (int i = 1; i < 5; i++) {
    int f = min(u, i);
    int s = max(u, i);
    if (!adj[f][s].empty() && !visited[i]) dfs(i);
    for (auto c : adj[f][s]) {
      cost += c;
      if (f == s) cost += c;
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, v, c;
    cin >> u >> c >> v;
    if (u > v) swap(u, v);
    adj[u][v].insert(c);
  }
  int ans = 0;
  bool cond = 1;
  for (int i = 1; i < 5; i++) {
    cost = 0;
    if (i != 1 && !visited[i]) cond = 0;
    if (!visited[i]) dfs(i);
    ans = max(ans, cost / 2);
  }
  for (int i = 1; i < 5; i++) {
    int degree = 0;
    for (int j = 1; j < 5; j++) {
      int f = min(i, j);
      int s = max(i, j);
      degree += int((adj[f][s]).size());
      if (i == j) degree += int((adj[f][s]).size());
    }
    if (degree % 2 == 0) cond = 0;
  }
  if (cond) {
    ans = 0;
    for (int i = 1; i < 5; i++) {
      for (int j = 1; j < 5; j++) {
        int f = min(i, j);
        int s = max(i, j);
        if (adj[f][s].empty() || i == j) continue;
        int temp = *adj[f][s].begin();
        adj[f][s].erase(temp);
        memset(visited, 0, sizeof(visited));
        for (int k = 1; k < 5; k++) {
          cost = 0;
          if (!visited[k]) dfs(k);
          ans = max(ans, cost / 2);
        }
        adj[f][s].insert(temp);
      }
    }
  }
  cout << ans;
  return 0;
}
