#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1000000001;
const long long INF = 1e18;
const long long MOD = 1000000007;
const double pi = 3.14159265358979323846;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
class UnionFind {
 public:
  int n;
  vector<int> par;
  vector<int> ran;
  vector<int> num;
  UnionFind(int _n) {
    n = _n;
    par.resize(n);
    ran.resize(n);
    num.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      ran[i] = 0;
      num[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    int numsum = num[x] + num[y];
    if (x == y) {
      return;
    }
    if (ran[x] < ran[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (ran[x] == ran[y]) {
        ran[x]++;
      }
    }
    num[x] = num[y] = numsum;
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  int n;
  cin >> n;
  vector<vector<vector<int> > > G(4, vector<vector<int> >(4));
  for (long long i = 0; i < (long long)(n); i++) {
    int u, x, v;
    cin >> u >> x >> v;
    u--;
    v--;
    if (u > v) {
      swap(u, v);
    }
    G[u][v].push_back(x);
  }
  vector<int> num(4);
  vector<int> sum(4);
  for (long long i = 0; i < (long long)(4); i++) {
    for (long long j = (long long)i; j < (long long)4; j++) {
      num[i] += G[i][j].size();
      num[j] += G[i][j].size();
      for (long long k = 0; k < (long long)(G[i][j].size()); k++) {
        sum[i] += G[i][j][k];
      }
    }
  }
  for (long long i = 0; i < (long long)(4); i++) {
    for (long long j = (long long)i; j < (long long)4; j++) {
      sort(G[i][j].begin(), G[i][j].end());
    }
  }
  int ans = 0;
  for (long long mask = 0; mask < (long long)(1 << 16); mask++) {
    vector<int> num2 = num;
    vector<int> sum2 = sum;
    bool flag = true;
    UnionFind uf(4);
    for (long long i = 0; i < (long long)(4); i++) {
      for (long long j = (long long)i; j < (long long)4; j++) {
        int k = i * 4 + j;
        if (mask & (1 << k)) {
          if (G[i][j].size() >= 2) {
            uf.unite(i, j);
          }
        } else {
          if (G[i][j].size() >= 1) {
            uf.unite(i, j);
          }
        }
        if ((mask & (1 << k))) {
          if (G[i][j].size() == 0) {
            flag = false;
            i = j = 100;
            break;
          }
          num2[i]--;
          num2[j]--;
          sum2[i] -= G[i][j][0];
        }
      }
    }
    if (!flag) {
      continue;
    }
    for (long long i = 0; i < (long long)(4); i++) {
      int gu = 0, ki = 0;
      int temp = 0;
      for (long long j = 0; j < (long long)(4); j++) {
        if (uf.find(j) == i) {
          temp += sum2[j];
          if (num2[j] % 2 == 0) {
            gu++;
          } else {
            ki++;
          }
        }
      }
      if (ki == 0 || ki == 2) {
        chmax(ans, temp);
      }
    }
  }
  cout << ans << endl;
}
