#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n, forbidden, f[N], deg[N], sum[N], sol, x[N], y[N], q[N];
vector<int> v[N];
void dfs(int c, int z) {
  f[c] = z;
  for (auto i : v[c])
    if (!f[i]) dfs(i, z);
}
bool disconnected() {
  int z = 0;
  for (int i = 1; i <= 4; i++) f[i] = 0;
  for (int i = 1; i <= 4; i++)
    if (!f[i]) z++, dfs(i, z);
  return z > 1;
}
void check() {
  int z = 0;
  for (int i = 1; i <= 4; i++) f[i] = 0;
  for (int i = 1; i <= 4; i++)
    if (!f[i]) z++, dfs(i, z);
  for (int i = 1; i <= z; i++) sum[i] = 0;
  for (int i = 1; i <= n; i++)
    if (forbidden != i) sum[f[x[i]]] += q[i];
  for (int i = 1; i <= z; i++) sol = max(sol, sum[i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &x[i], &q[i], &y[i]);
    deg[x[i]]++;
    deg[y[i]]++;
  }
  int summing = 0;
  for (int i = 1; i <= 4; i++) summing += deg[i] & 1;
  if (summing == 4) {
    for (int i = 1; i <= n; i++)
      if (x[i] != y[i]) {
        forbidden = i;
        for (int j = 1; j <= 4; j++) v[j].clear();
        for (int j = 1; j <= n; j++)
          if (j != i) {
            v[x[j]].push_back(y[j]);
            v[y[j]].push_back(x[j]);
          }
        check();
      }
  }
  forbidden = 0;
  for (int i = 1; i <= 4; i++) v[i].clear();
  for (int i = 1; i <= n; i++) {
    v[x[i]].push_back(y[i]);
    v[y[i]].push_back(x[i]);
  }
  if (summing != 4 || disconnected()) check();
  printf("%d", sol);
  return 0;
}
