#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1, mod) % mod;
}
vector<int> edges[6];
int bonus[4];
int U[6] = {0, 0, 0, 1, 1, 2}, V[6] = {1, 2, 3, 2, 3, 3};
int rev[4][3] = {{0, 1, 2}, {0, 3, 4}, {1, 3, 5}, {2, 4, 5}};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  memset(bonus, 0, sizeof(bonus));
  for (int i = 0; i < n; i++) {
    int cost, x, y;
    cin >> x >> cost >> y;
    x--, y--;
    if (x > y) swap(x, y);
    if (x == y)
      bonus[x] += cost;
    else
      for (int j = 0; j < 6; j++)
        if (U[j] == x && V[j] == y) edges[j].push_back(cost);
  }
  int dp[4][edges[0].size() + 1][edges[1].size() + 1][edges[2].size() + 1]
        [edges[3].size() + 1][edges[4].size() + 1][edges[5].size() + 1];
  memset(dp, -1, sizeof(dp));
  int ans = 0;
  int vis[6];
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < 4; i++) dp[i][0][0][0][0][0][0] = 0;
  for (int i = 0; i < 6; i++)
    sort(edges[i].begin(), edges[i].end(), greater<int>());
  for (vis[0] = 0; vis[0] <= edges[0].size(); vis[0]++)
    for (vis[1] = 0; vis[1] <= edges[1].size(); vis[1]++)
      for (vis[2] = 0; vis[2] <= edges[2].size(); vis[2]++)
        for (vis[3] = 0; vis[3] <= edges[3].size(); vis[3]++)
          for (vis[4] = 0; vis[4] <= edges[4].size(); vis[4]++)
            for (vis[5] = 0; vis[5] <= edges[5].size(); vis[5]++)
              for (int i = 0; i < 4; i++) {
                if (dp[i][vis[0]][vis[1]][vis[2]][vis[3]][vis[4]][vis[5]] == -1)
                  continue;
                int cnt = 0;
                for (int e = 0; e < 3; e++) cnt += vis[rev[i][e]];
                if (cnt < 2)
                  dp[i][vis[0]][vis[1]][vis[2]][vis[3]][vis[4]][vis[5]] +=
                      bonus[i];
                ans = max(
                    ans, dp[i][vis[0]][vis[1]][vis[2]][vis[3]][vis[4]][vis[5]]);
                for (int e = 0; e < 3; e++) {
                  int edge = rev[i][e];
                  if (vis[edge] < edges[edge].size()) {
                    int w = U[edge] ^ V[edge] ^ i;
                    int sum =
                        dp[i][vis[0]][vis[1]][vis[2]][vis[3]][vis[4]][vis[5]] +
                        edges[edge][vis[edge]];
                    vis[edge]++;
                    if (dp[w][vis[0]][vis[1]][vis[2]][vis[3]][vis[4]][vis[5]] <
                        sum)
                      dp[w][vis[0]][vis[1]][vis[2]][vis[3]][vis[4]][vis[5]] =
                          sum;
                    vis[edge]--;
                  }
                }
              }
  cout << ans << endl;
  return 0;
}
