#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool checkMax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
int n, degree[5], f[5], val[5];
char a[5], b[5];
vector<pair<int, int> > G[5];
inline void add(int u, int v, int w) {
  G[u].push_back(make_pair(w, v)), G[v].push_back(make_pair(w, u));
  ++degree[u], ++degree[v];
}
inline int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int nodes[5], top;
inline bool check() {
  int e = 0;
  for (register int i = 1; i <= top; ++i) {
    int u = nodes[i];
    e += (degree[u] & 1);
  }
  return !e || e == 2;
}
inline int solve(int anc) {
  top = 0;
  for (register int i = 1; i <= 4; ++i) {
    if (find(i) == anc) {
      nodes[++top] = i;
    }
  }
  if (!top) {
    return 0;
  }
  int res = 0;
  for (register int i = 1; i <= top; ++i) {
    int u = nodes[i];
    for (register int j = 0; j < G[u].size(); ++j) {
      res += G[u][j].first;
    }
  }
  res >>= 1;
  for (register int i = 1; i <= top; ++i) {
    int u = nodes[i];
    res += val[u];
  }
  if (check()) {
    return res;
  }
  int final = 0;
  for (register int i = 1; i <= top; ++i) {
    int u = nodes[i];
    if (!G[u].size()) {
      continue;
    }
    for (register int j = 0; j < G[u].size(); ++j) {
      res -= G[u][j].first;
      --degree[u], --degree[G[u][j].second];
      if (degree[u] == 0) {
        res -= val[u];
      }
      if (degree[G[u][j].second] == 0) {
        res -= val[G[u][j].second];
      }
      if (check()) {
        checkMax(final, res);
      }
      if (degree[u] == 0) {
        res += val[u];
      }
      if (degree[G[u][j].second] == 0) {
        res += val[G[u][j].second];
      }
      res += G[u][j].first;
      ++degree[u], ++degree[G[u][j].second];
    }
  }
  return final;
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= 4; ++i) {
    f[i] = i;
  }
  for (register int i = 1; i <= n; ++i) {
    int w, u, v;
    scanf("%d%d%d", &u, &w, &v);
    if (u == v) {
      val[u] += w;
    } else {
      add(u, v, w);
    }
    if (find(u) ^ find(v)) {
      f[find(u)] = find(v);
    }
  }
  for (register int i = 1; i <= 4; ++i) {
    sort(G[i].begin(), G[i].end());
  }
  int ans = 0;
  for (register int i = 1; i <= 4; ++i) {
    checkMax(ans, solve(i));
  }
  printf("%d\n", ans);
  return 0;
}
