#include <bits/stdc++.h>
using namespace std;
int n, m, k, y, x, t, z, tot;
string s;
int dp[3205050][5], b[5], d[15][15], to_add[15][15], h[5], period;
int sz[5][5];
vector<int> g[5][5];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    if (x > z) swap(x, z);
    if (x == z) {
      b[x] += y;
      continue;
    }
    g[x][z].push_back(y);
  }
  int max_val = 1;
  for (int i = 1; i <= 3; i++)
    for (int j = i + 1; j <= 4; j++) {
      sort(g[i][j].begin(), g[i][j].end());
      reverse(g[i][j].begin(), g[i][j].end());
      sz[i][j] = g[i][j].size() + 1;
      to_add[i][j] = max_val;
      if (i == 3) period = max_val + 15;
      max_val *= sz[i][j];
    }
  int ans = 0;
  for (int i = 1; i <= 4; i++) ans = max(ans, b[i]);
  for (int i = 1; i <= 3200000; i++)
    for (int j = 1; j <= 4; j++) dp[i][j] = -1000000007;
  for (int i = 0; i < max_val; i++) {
    int tmp_sz = 0;
    int cur_val = i;
    for (int k = 1; k <= 3; k++)
      for (int j = k + 1; j <= 4; j++) {
        d[k][j] = cur_val % sz[k][j];
        cur_val /= sz[k][j];
      }
    for (int j = 1; j <= 4; j++) h[j] = 0;
    for (int j = 1; j <= 4; j++) {
      int cur_dp = dp[i % period][j];
      for (int k = 1; k <= 4; k++) {
        if (j == k) continue;
        int x = j, y = k;
        if (x > y) swap(x, y);
        int idx = (i + to_add[x][y]) % period;
        if (d[x][y]) {
          h[x] = h[y] = 1;
        }
        if (d[x][y] + 1 == sz[x][y]) continue;
        dp[idx][k] = max(dp[idx][k], cur_dp + g[x][y][d[x][y]]);
      }
    }
    int mag = 0;
    for (int j = 1; j <= 4; j++) mag += h[j] * b[j];
    for (int j = 1; j <= 4; j++) {
      ans = max(ans, dp[i % period][j] + mag);
      dp[i % period][j] = -1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
