#include <bits/stdc++.h>
using namespace std;
vector<int> v[10];
int n;
map<vector<int>, int> d[5];
int e[10][2] = {{1, 2}, {2, 4}, {4, 3}, {3, 1}, {1, 4},
                {2, 3}, {1, 1}, {2, 2}, {3, 3}, {4, 4}};
int to[5][5];
int f(vector<int> edge, int k) {
  if (d[k].count(edge)) return d[k][edge];
  int res = 0;
  for (int i = 1; i <= 4; i++) {
    if (edge[to[k][i]]) {
      --edge[to[k][i]];
      res = max(res, f(edge, i) + v[to[k][i]][edge[to[k][i]]]);
      ++edge[to[k][i]];
    }
  }
  return d[k][edge] = res;
}
int main() {
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 4; j++) {
      for (int k = 0; k < 10; k++) {
        if (e[k][0] == i && e[k][1] == j)
          to[i][j] = k;
        else if (e[k][0] == j && e[k][1] == i)
          to[i][j] = k;
      }
    }
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int l, r, w;
    scanf("%d %d %d", &l, &w, &r);
    if (l == r) {
      if (v[to[l][r]].empty())
        v[to[l][r]].push_back(w);
      else
        v[to[l][r]].back() += w;
    } else
      v[to[l][r]].push_back(w);
  }
  vector<int> edge;
  for (int i = 0; i < 10; i++) {
    sort(v[i].begin(), v[i].end());
    vector<int> temp;
    if (v[i].size() > 1) {
      if (v[i].size() % 2 == 0) {
        int sum = 0;
        for (int j = 1; j < v[i].size(); j++) sum += v[i][j];
        int pre = v[i][0];
        v[i] = vector<int>();
        v[i].push_back(pre);
        v[i].push_back(sum);
      } else {
        int sum = 0, p1 = v[i][0], p2 = v[i][1];
        for (int j = 2; j < v[i].size(); j++) sum += v[i][j];
        v[i] = vector<int>();
        v[i].push_back(p1);
        v[i].push_back(p2);
        v[i].push_back(sum);
      }
    }
    edge.push_back(v[i].size());
  }
  int res = 0;
  for (int i = 1; i <= 4; i++) {
    res = max(res, f(edge, i));
  }
  printf("%d\n", res);
  return 0;
}
