#include <bits/stdc++.h>
using namespace std;
const int N = 4;
const int M = N * (N - 1) / 2;
class Solution {
 public:
  int maximumSubsequence(vector<vector<int>>& blocks) {
    vector<vector<vector<int>>> edges(N, vector<vector<int>>(N));
    vector<vector<int>> sums(N, vector<int>(N, 0));
    for (auto& bl : blocks) {
      int c1 = bl[0];
      int c2 = bl[2];
      int v = bl[1];
      if (c1 > c2) {
        swap(c1, c2);
      }
      edges[c1][c2].push_back(v);
      sums[c1][c2] += v;
    }
    for (auto& vv : edges) {
      for (auto& v : vv) {
        sort(v.begin(), v.end());
      }
    }
    int res = 0;
    vector<bool> used(N, false);
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < (1 << M); ++j) {
        fill(used.begin(), used.end(), false);
        used[i] = true;
        for (int _ = 0; _ < M; ++_) {
          for (int u = 0; u < N; ++u) {
            if (used[u]) {
              for (int v = 0; v < N; ++v) {
                int sub = (j & (1 << key(u, v))) ? 1 : 0;
                int x = min(u, v), y = max(u, v);
                if (edges[x][y].size() > sub) {
                  used[v] = true;
                }
              }
            }
          }
        }
        vector<int> degrees(N, 0);
        int sum = 0;
        for (int u = 0; u < N; ++u) {
          for (int v = u; v < N; ++v) {
            if (used[u] && used[v]) {
              int sub = (j & (1 << key(u, v))) ? 1 : 0;
              if (edges[u][v].size() > sub) {
                degrees[u] += edges[u][v].size() - sub;
                degrees[v] += edges[u][v].size() - sub;
                sum += sums[u][v];
                if (sub == 1) {
                  sum -= edges[u][v][0];
                }
              }
            }
          }
        }
        int oddDegreeNodes = 0;
        for (auto d : degrees) {
          if (d % 2 == 1) {
            ++oddDegreeNodes;
          }
        }
        if (oddDegreeNodes <= 2) {
          res = max(res, sum);
        }
      }
    }
    return res;
  }

 private:
  int key(int x, int y) {
    if (x > y) {
      swap(x, y);
    }
    if (x == y) {
      return M;
    }
    int res = 0;
    for (int i = 0, n = N - 1; i < x; ++i, --n) {
      res += n;
    }
    res += y - x - 1;
    return res;
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> blocks;
  blocks.reserve(n);
  for (int i = 0, c1 = 0, v = 0, c2 = 0; i < n; ++i) {
    cin >> c1 >> v >> c2;
    blocks.emplace_back(vector<int>{c1 - 1, v, c2 - 1});
  }
  Solution sol;
  cout << sol.maximumSubsequence(blocks) << endl;
  return 0;
}
