#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = (long long)INF * INF;
const int MAX = 107;
int dp[MAX][1 << 4][1 << 4][1 << 8];
int trans[1 << 8][4][4];
int C1[MAX], C2[MAX];
int val[MAX];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = (0); i < (n + 1); ++i)
    for (int mask = (0); mask < (1 << 4); ++mask)
      for (int used = (0); used < (1 << 4); ++used)
        for (int prof = (0); prof < (1 << 8); ++prof)
          dp[i][mask][used][prof] = -INF;
  dp[0][0][0][1 * 4 + 2 * 4 * 4 + 3 * 4 * 4 * 4] = 0;
  for (int prof = (0); prof < (1 << 8); ++prof)
    for (int col1 = (0); col1 < (4); ++col1)
      for (int col2 = (0); col2 < (4); ++col2) {
        int res[4];
        int curProf = prof;
        for (int i = (0); i < (4); ++i) {
          res[i] = curProf & 3;
          curProf >>= 2;
        }
        int comp = res[col2];
        for (int i = (0); i < (4); ++i) {
          if (res[i] == comp) res[i] = res[col1];
        }
        for (int i = (0); i < (4); ++i)
          trans[prof][col1][col2] |= res[i] << (2 * i);
      }
  for (int i = (1); i < (n + 1); ++i) {
    cin >> C1[i] >> val[i] >> C2[i];
    C1[i]--;
    C2[i]--;
  }
  for (int i = (0); i < (n); ++i) {
    for (int mask = (0); mask < (1 << 4); ++mask) {
      for (int used = (0); used < (1 << 4); ++used)
        for (int prof = (0); prof < (1 << 8); ++prof) {
          dp[i + 1][mask][used][prof] =
              max(dp[i + 1][mask][used][prof], dp[i][mask][used][prof]);
          int col1 = C1[i + 1], col2 = C2[i + 1];
          dp[i + 1][mask ^ (1 << col1) ^ (1 << col2)]
            [used | (1 << col1) | (1 << col2)][trans[prof][col1][col2]] = max(
                dp[i + 1][mask ^ (1 << col1) ^ (1 << col2)]
                  [used | (1 << col1) | (1 << col2)][trans[prof][col1][col2]],
                dp[i][mask][used][prof] + val[i + 1]);
        }
    }
  }
  int ans = -INF;
  for (int mask = (0); mask < (1 << 4); ++mask) {
    int cnt = __builtin_popcount(mask);
    if (cnt != 0 && cnt != 2) continue;
    for (int used = (0); used < (1 << 4); ++used) {
      for (int prof = (0); prof < (1 << 8); ++prof) {
        bool ok = true;
        int comp = -1;
        for (int i = (0); i < (4); ++i) {
          if (!(used & (1 << i))) continue;
          int curComp = (prof >> (2 * i)) & 3;
          if (comp != -1 && comp != curComp) ok = false;
          comp = curComp;
        }
        if (ok) ans = max(ans, dp[n][mask][used][prof]);
      }
    }
  }
  cout << ans;
  return 0;
}
