#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> edge[105];
int n, deg[5], visit[5], cnt, res, a[5][5];
int dfs(int u) {
  visit[u] = 1;
  cnt += deg[u] % 2;
  int tmp = a[u][u] * 2;
  for (int v = 1; v <= 4; v++) {
    if (a[u][v] == 0 || v == u) continue;
    if (visit[v] == 0) tmp += dfs(v);
    tmp += a[u][v];
  }
  return tmp;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int u, v, c;
    cin >> u >> c >> v;
    if (u == v)
      a[u][v] += c;
    else {
      a[u][v] += c;
      a[v][u] += c;
      deg[u]++;
      deg[v]++;
    }
    edge[i] = make_pair(make_pair(u, v), c);
  }
  for (int i = 1; i <= 4; i++) {
    if (visit[i] == 0) {
      cnt = 0;
      int tmp = dfs(i) / 2;
      if (cnt == 0 || cnt == 2) res = max(res, tmp);
    }
  }
  if (cnt != 4) {
    cout << res;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int u = edge[i].first.first, v = edge[i].first.second, c = edge[i].second;
    if (u == v) continue;
    a[u][v] -= c;
    a[v][u] -= c;
    memset(visit, 0, sizeof visit);
    for (int j = 1; j <= 4; j++)
      if (visit[j] == 0) res = max(res, dfs(j) / 2);
    a[u][v] += c;
    a[v][u] += c;
  }
  cout << res;
}
