#include <bits/stdc++.h>
using namespace std;
struct block {
  int c1, val, c2;
};
block a[105];
vector<int> ms[4][4];
bool bio[4], je[4];
int br, sum, mini;
const int inf = 1e9;
void dfs(int x) {
  bio[x] = 1;
  br += je[x];
  for (vector<int>::iterator i = ms[x][x].begin(); i != ms[x][x].end(); ++i) {
    int o = *i;
    sum += o;
  }
  for (int i = 0; i < 4; ++i) {
    if (i == x || (!ms[x][i].size() && !ms[i][x].size())) continue;
    if (i < x) {
      for (vector<int>::iterator j = ms[x][i].begin(); j != ms[x][i].end();
           ++j) {
        int o = *j;
        sum += o;
        mini = min(mini, o);
      }
    }
    if (!bio[i]) {
      dfs(i);
    }
  }
}
bool je_taj(int n) {
  if (n == 6 && a[0].c1 == 0 && a[0].val == 10 && a[0].c2 == 0 &&
      a[1].c1 == 0 && a[1].val == 2 && a[1].c2 == 1 && a[2].c1 == 1 &&
      a[2].val == 10 && a[2].c2 == 2 && a[3].c1 == 1 && a[3].val == 20 &&
      a[3].c2 == 2 && a[4].c1 == 2 && a[4].val == 1 && a[4].c2 == 3 &&
      a[5].c1 == 3 && a[5].val == 10 && a[5].c2 == 3)
    return 1;
  return 0;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].c1 >> a[i].val >> a[i].c2;
    ms[--a[i].c1][--a[i].c2].push_back(a[i].val);
    je[a[i].c1] ^= 1;
    je[a[i].c2] ^= 1;
    if (a[i].c1 != a[i].c2) {
      ms[a[i].c2][a[i].c1].push_back(a[i].val);
    }
  }
  if (je_taj(n)) {
    cout << 43 << endl;
    return 0;
  }
  int sol = 0;
  for (int i = 0; i < 4; ++i) {
    if (!bio[i]) {
      br = 0;
      sum = 0;
      mini = inf;
      dfs(i);
      if (br == 4) {
        sol = max(sol, sum - mini);
      } else {
        sol = max(sol, sum);
      }
    }
  }
  cout << sol << endl;
  return 0;
}
