#include <bits/stdc++.h>
using namespace std;
template <class U, class T>
void Max(U &first, T second) {
  if (first < second) first = second;
}
template <class U, class T>
void Min(U &first, T second) {
  if (first > second) first = second;
}
template <class T>
void add(int &a, T b) {
  a = (a + b) % 1000000007;
}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 1000000007;
    a = 1LL * a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
int pow(int a, int b, int c) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % c;
    a = 1LL * a * a % c;
    b >>= 1;
  }
  return ans;
}
int W[4];
int g[4][4], sz, dp[1 << 12][4], vis[4], is[4][4], e[4][4], f[4][4];
pair<int, int> q[10];
int main() {
  int ca = 0, T, k, i, j, m = 0, n, K;
  scanf("%d", &n);
  int w;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++) f[i][j] = 1000000007;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &j, &w, &k);
    j--, k--;
    if (j > k) swap(j, k);
    if (j == k) {
      W[j] += w;
    } else
      e[j][k]++, g[j][k] += w, Min(f[j][k], w);
  }
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++)
      if (e[i][j]) {
        q[sz++] = {i, j};
        q[sz++] = {j, i};
      }
  }
  for (int i = 0; i < 4; i++) {
    int res = W[i];
    for (int j = 0; j < i; j++)
      if (e[j][i] % 2 == 0) res += g[j][i];
    for (int j = i + 1; j < 4; j++)
      if (e[i][j] % 2 == 0) res += g[i][j];
    Max(ans, res);
  }
  for (int i = 0; i < sz; i++) dp[1 << i][q[i].second] = 1;
  for (int i = 1; i < (1 << sz); i++) {
    for (int j = 0; j < 4; j++)
      if (dp[i][j] > 0) {
        for (int k = 0; k < sz; k++)
          if (!(i >> k & 1) && q[k].first == j) {
            dp[i | 1 << k][q[k].second] = 1;
          }
      }
  }
  for (int i = 1; i < (1 << sz); i++) {
    for (int j = 0; j < 4; j++)
      if (dp[i][j]) {
        memset(is, 0, sizeof(is));
        for (int k = 0; k < sz; k++)
          if (i >> k & 1) {
            int first = q[k].first, second = q[k].second;
            if (first > second) swap(first, second);
            is[first][second]++;
          }
        int ok = 1, res = 0;
        memset(vis, 0, sizeof(vis));
        for (int l = 0; l < 4; l++)
          for (int r = l + 1; r < 4; r++)
            if (is[l][r]) {
              vis[l] = vis[r] = 1;
              if (is[l][r] > e[l][r]) {
                ok = 0;
                break;
              }
              if (is[l][r] == 1) {
                if (e[l][r] & 1)
                  res += g[l][r];
                else
                  res += g[l][r] - f[l][r];
              } else {
                if (e[l][r] & 1)
                  res += g[l][r] - f[l][r];
                else
                  res += g[l][r];
              }
            }
        if (ok)
          for (int i = 0; i < 4; i++)
            if (vis[i]) res += W[i];
        if (ok) Max(ans, res);
      }
  }
  printf("%d\n", ans);
}
