#include <bits/stdc++.h>
using namespace std;
vector<long long int> graph[5][5];
long long int sum[5][5];
int regraph[5][5], visit_regraph[5][5];
int visited[5];
long long int maxSum;
void dfs(int cur) {
  bool found = false;
  for (int i = 1; i <= 4; i++) {
    if (i != cur && visit_regraph[cur][i] < regraph[cur][i]) {
      found = true;
      visited[i]++;
      visit_regraph[cur][i]++;
      visit_regraph[i][cur]++;
      dfs(i);
      visited[i]--;
      visit_regraph[cur][i]--;
      visit_regraph[i][cur]--;
    }
  }
  if (found) return;
  long long int s = 0;
  for (int i = 1; i <= 4; i++) {
    if (visited[i] > 0) s += sum[i][i];
  }
  for (int i = 1; i <= 4; i++)
    for (int j = i + 1; j <= 4; j++) {
      if (regraph[i][j] > 0) {
        if (visit_regraph[i][j] == regraph[i][j])
          s += sum[i][j];
        else if (visit_regraph[i][j] < regraph[i][j] && visited[i] > 0 &&
                 visited[j] > 0) {
          s += sum[i][j];
          for (int k = 0; k < regraph[i][j] - visit_regraph[i][j]; k++)
            s -= graph[i][j][k];
        }
      }
    }
  maxSum = max(maxSum, s);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  int c1, c2;
  long long int val;
  for (int i = 0; i < n; i++) {
    cin >> c1 >> val >> c2;
    if (c1 > c2) swap(c1, c2);
    graph[c1][c2].push_back(val);
    sum[c1][c2] += val;
  }
  for (int i = 1; i <= 4; i++)
    for (int j = i; j <= 4; j++) sort(graph[i][j].begin(), graph[i][j].end());
  for (int i = 1; i <= 4; i++)
    for (int j = i + 1; j <= 4; j++) {
      int x;
      if (graph[i][j].size() == 0)
        x = 0;
      else {
        x = graph[i][j].size() % 2;
        if (x == 0) x = 2;
      }
      regraph[i][j] = regraph[j][i] = x;
    }
  maxSum = -1;
  for (int i = 1; i <= 4; i++) {
    visited[i]++;
    dfs(i);
    visited[i]--;
  }
  cout << maxSum << endl;
  return 0;
}
