#include <bits/stdc++.h>
using namespace std;
int bigint = 10000000;
int m;
vector<int> e[11][11];
int deg[11];
bool visd[11];
bool conn[11][11];
int s[11][11];
bool chk_conn(int x, int y) {
  bool c[11][11];
  memset(c, false, sizeof c);
  for (int i = 1; i <= 4; i++)
    for (int j = i + 1; j <= 4; j++)
      if (!(i == x && j == y) && e[i][j].size() > 0) c[i][j] = c[j][i] = true;
  for (int k = 1; k <= 4; k++)
    for (int i = 1; i <= 4; i++)
      for (int j = 1; j <= 4; j++)
        if (c[i][k] && c[k][j]) c[i][j] = true;
  return c[x][y];
}
int calc() {
  int mi[11][11];
  for (int i = 1; i <= 4; i++)
    for (int j = i; j <= 4; j++) {
      mi[i][j] = mi[j][i] = (i == j) ? 0 : bigint;
      if (i <= j) sort(e[i][j].begin(), e[i][j].end());
      if ((int)e[i][j].size() > 0) mi[i][j] = mi[j][i] = e[i][j][0];
    }
  for (int k = 1; k <= 4; k++)
    for (int i = 1; i <= 4; i++)
      for (int j = 1; j <= 4; j++)
        mi[i][j] = min(mi[i][j], mi[i][k] + mi[k][j]);
  int ans = bigint;
  for (int i = 1; i <= 4; i++)
    for (int j = i + 1; j <= 4; j++)
      if (e[i][j].size() > 1 || chk_conn(i, j)) ans = min(ans, mi[i][j]);
  return ans;
}
int main() {
  scanf("%d", &m);
  for (int i = 1; i <= 4; i++) {
    deg[i] = 0;
    for (int j = 1; j <= 4; j++) e[i][j].clear();
  }
  memset(conn, false, sizeof conn);
  for (int i = 0; i < m; i++) {
    int x, v, y;
    scanf("%d%d%d", &x, &v, &y);
    if (x > y) swap(x, y);
    e[x][y].push_back(v);
    s[x][y] += v;
    deg[x]++;
    deg[y]++;
    conn[x][y] = conn[y][x] = true;
  }
  for (int k = 1; k <= 4; k++)
    for (int i = 1; i <= 4; i++)
      for (int j = 1; j <= 4; j++)
        if (conn[i][k] && conn[k][j]) conn[i][j] = true;
  int ans = 0;
  memset(visd, false, sizeof visd);
  for (int i = 1; i <= 4; i++)
    if (!visd[i]) {
      int q[11], r = 0;
      for (int j = 1; j <= 4; j++)
        if (j == i || conn[i][j]) q[r++] = j;
      int res = 0, odd = 0;
      for (int x = 0; x < r; x++) {
        int id = q[x];
        visd[id] = true;
        if (deg[id] % 2 != 0) odd++;
        for (int y = x; y < r; y++) res += s[id][q[y]];
      }
      if (r == 4 && odd == 4) res -= calc();
      ans = max(ans, res);
    }
  printf("%d\n", ans);
  return 0;
}
